intel: Add support for IPv6 IP-in-IP offload
[deliverable/linux.git] / drivers / net / ethernet / intel / i40evf / i40evf_virtchnl.c
CommitLineData
62683ab5
GR
1/*******************************************************************************
2 *
3 * Intel Ethernet Controller XL710 Family Linux Virtual Function Driver
ef8693eb 4 * Copyright(c) 2013 - 2014 Intel Corporation.
62683ab5
GR
5 *
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 *
b831607d
JB
15 * 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/>.
17 *
62683ab5
GR
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 "i40evf.h"
28#include "i40e_prototype.h"
29
30/* busy wait delay in msec */
31#define I40EVF_BUSY_WAIT_DELAY 10
32#define I40EVF_BUSY_WAIT_COUNT 50
33
34/**
35 * i40evf_send_pf_msg
36 * @adapter: adapter structure
37 * @op: virtual channel opcode
38 * @msg: pointer to message buffer
39 * @len: message length
40 *
41 * Send message to PF and print status if failure.
42 **/
43static int i40evf_send_pf_msg(struct i40evf_adapter *adapter,
44 enum i40e_virtchnl_ops op, u8 *msg, u16 len)
45{
46 struct i40e_hw *hw = &adapter->hw;
47 i40e_status err;
48
ef8693eb
MW
49 if (adapter->flags & I40EVF_FLAG_PF_COMMS_FAILED)
50 return 0; /* nothing to see here, move along */
51
62683ab5
GR
52 err = i40e_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL);
53 if (err)
f1c7e72e
SN
54 dev_err(&adapter->pdev->dev, "Unable to send opcode %d to PF, err %s, aq_err %s\n",
55 op, i40evf_stat_str(hw, err),
56 i40evf_aq_str(hw, hw->aq.asq_last_status));
62683ab5
GR
57 return err;
58}
59
60/**
61 * i40evf_send_api_ver
62 * @adapter: adapter structure
63 *
64 * Send API version admin queue message to the PF. The reply is not checked
65 * in this function. Returns 0 if the message was successfully
66 * sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
67 **/
68int i40evf_send_api_ver(struct i40evf_adapter *adapter)
69{
70 struct i40e_virtchnl_version_info vvi;
71
72 vvi.major = I40E_VIRTCHNL_VERSION_MAJOR;
73 vvi.minor = I40E_VIRTCHNL_VERSION_MINOR;
74
75 return i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_VERSION, (u8 *)&vvi,
76 sizeof(vvi));
77}
78
79/**
80 * i40evf_verify_api_ver
81 * @adapter: adapter structure
82 *
83 * Compare API versions with the PF. Must be called after admin queue is
6a8e93db
MW
84 * initialized. Returns 0 if API versions match, -EIO if they do not,
85 * I40E_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors
86 * from the firmware are propagated.
62683ab5
GR
87 **/
88int i40evf_verify_api_ver(struct i40evf_adapter *adapter)
89{
90 struct i40e_virtchnl_version_info *pf_vvi;
91 struct i40e_hw *hw = &adapter->hw;
92 struct i40e_arq_event_info event;
f8d4db35 93 enum i40e_virtchnl_ops op;
62683ab5
GR
94 i40e_status err;
95
1001dc37
MW
96 event.buf_len = I40EVF_MAX_AQ_BUF_SIZE;
97 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
62683ab5
GR
98 if (!event.msg_buf) {
99 err = -ENOMEM;
100 goto out;
101 }
102
f8d4db35
MW
103 while (1) {
104 err = i40evf_clean_arq_element(hw, &event, NULL);
105 /* When the AQ is empty, i40evf_clean_arq_element will return
106 * nonzero and this loop will terminate.
107 */
108 if (err)
109 goto out_alloc;
110 op =
111 (enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
112 if (op == I40E_VIRTCHNL_OP_VERSION)
113 break;
114 }
115
62683ab5
GR
116
117 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
6a8e93db 118 if (err)
62683ab5 119 goto out_alloc;
62683ab5 120
f8d4db35 121 if (op != I40E_VIRTCHNL_OP_VERSION) {
6a8e93db 122 dev_info(&adapter->pdev->dev, "Invalid reply type %d from PF\n",
f8d4db35 123 op);
62683ab5
GR
124 err = -EIO;
125 goto out_alloc;
126 }
127
128 pf_vvi = (struct i40e_virtchnl_version_info *)event.msg_buf;
ee1693e5
MW
129 adapter->pf_version = *pf_vvi;
130
131 if ((pf_vvi->major > I40E_VIRTCHNL_VERSION_MAJOR) ||
132 ((pf_vvi->major == I40E_VIRTCHNL_VERSION_MAJOR) &&
133 (pf_vvi->minor > I40E_VIRTCHNL_VERSION_MINOR)))
62683ab5
GR
134 err = -EIO;
135
136out_alloc:
137 kfree(event.msg_buf);
138out:
139 return err;
140}
141
142/**
143 * i40evf_send_vf_config_msg
144 * @adapter: adapter structure
145 *
146 * Send VF configuration request admin queue message to the PF. The reply
147 * is not checked in this function. Returns 0 if the message was
148 * successfully sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
149 **/
150int i40evf_send_vf_config_msg(struct i40evf_adapter *adapter)
151{
e6d038de
MW
152 u32 caps;
153
154 adapter->current_op = I40E_VIRTCHNL_OP_GET_VF_RESOURCES;
155 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_CONFIG;
156 caps = I40E_VIRTCHNL_VF_OFFLOAD_L2 |
157 I40E_VIRTCHNL_VF_OFFLOAD_RSS_AQ |
158 I40E_VIRTCHNL_VF_OFFLOAD_RSS_REG |
1f012279 159 I40E_VIRTCHNL_VF_OFFLOAD_VLAN |
b9eacec3
ASJ
160 I40E_VIRTCHNL_VF_OFFLOAD_WB_ON_ITR |
161 I40E_VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2;
162
e6d038de
MW
163 adapter->current_op = I40E_VIRTCHNL_OP_GET_VF_RESOURCES;
164 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_CONFIG;
165 if (PF_IS_V11(adapter))
166 return i40evf_send_pf_msg(adapter,
167 I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
168 (u8 *)&caps, sizeof(caps));
169 else
170 return i40evf_send_pf_msg(adapter,
171 I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
172 NULL, 0);
62683ab5
GR
173}
174
175/**
176 * i40evf_get_vf_config
177 * @hw: pointer to the hardware structure
178 * @len: length of buffer
179 *
180 * Get VF configuration from PF and populate hw structure. Must be called after
181 * admin queue is initialized. Busy waits until response is received from PF,
182 * with maximum timeout. Response from PF is returned in the buffer for further
183 * processing by the caller.
184 **/
185int i40evf_get_vf_config(struct i40evf_adapter *adapter)
186{
187 struct i40e_hw *hw = &adapter->hw;
188 struct i40e_arq_event_info event;
f8d4db35 189 enum i40e_virtchnl_ops op;
62683ab5 190 i40e_status err;
f8d4db35 191 u16 len;
62683ab5
GR
192
193 len = sizeof(struct i40e_virtchnl_vf_resource) +
194 I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource);
1001dc37
MW
195 event.buf_len = len;
196 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
62683ab5
GR
197 if (!event.msg_buf) {
198 err = -ENOMEM;
199 goto out;
200 }
201
f8d4db35 202 while (1) {
f8d4db35
MW
203 /* When the AQ is empty, i40evf_clean_arq_element will return
204 * nonzero and this loop will terminate.
205 */
206 err = i40evf_clean_arq_element(hw, &event, NULL);
207 if (err)
208 goto out_alloc;
209 op =
210 (enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
211 if (op == I40E_VIRTCHNL_OP_GET_VF_RESOURCES)
212 break;
62683ab5
GR
213 }
214
f8d4db35 215 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
1001dc37 216 memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
62683ab5
GR
217
218 i40e_vf_parse_hw_config(hw, adapter->vf_res);
219out_alloc:
220 kfree(event.msg_buf);
221out:
222 return err;
223}
224
225/**
226 * i40evf_configure_queues
227 * @adapter: adapter structure
228 *
229 * Request that the PF set up our (previously allocated) queues.
230 **/
231void i40evf_configure_queues(struct i40evf_adapter *adapter)
232{
233 struct i40e_virtchnl_vsi_queue_config_info *vqci;
234 struct i40e_virtchnl_queue_pair_info *vqpi;
cc052927 235 int pairs = adapter->num_active_queues;
62683ab5
GR
236 int i, len;
237
238 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
239 /* bail because we already have a command pending */
fb43201f
SN
240 dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
241 adapter->current_op);
62683ab5
GR
242 return;
243 }
244 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES;
245 len = sizeof(struct i40e_virtchnl_vsi_queue_config_info) +
246 (sizeof(struct i40e_virtchnl_queue_pair_info) * pairs);
a85088d8 247 vqci = kzalloc(len, GFP_KERNEL);
249c8b8d 248 if (!vqci)
62683ab5 249 return;
249c8b8d 250
62683ab5
GR
251 vqci->vsi_id = adapter->vsi_res->vsi_id;
252 vqci->num_queue_pairs = pairs;
253 vqpi = vqci->qpair;
254 /* Size check is not needed here - HW max is 16 queue pairs, and we
255 * can fit info for 31 of them into the AQ buffer before it overflows.
256 */
257 for (i = 0; i < pairs; i++) {
258 vqpi->txq.vsi_id = vqci->vsi_id;
259 vqpi->txq.queue_id = i;
0dd438d8
MW
260 vqpi->txq.ring_len = adapter->tx_rings[i].count;
261 vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
5d29896a
AS
262 vqpi->txq.headwb_enabled = 1;
263 vqpi->txq.dma_headwb_addr = vqpi->txq.dma_ring_addr +
264 (vqpi->txq.ring_len * sizeof(struct i40e_tx_desc));
62683ab5
GR
265
266 vqpi->rxq.vsi_id = vqci->vsi_id;
267 vqpi->rxq.queue_id = i;
0dd438d8
MW
268 vqpi->rxq.ring_len = adapter->rx_rings[i].count;
269 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
62683ab5
GR
270 vqpi->rxq.max_pkt_size = adapter->netdev->mtu
271 + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN;
0dd438d8 272 vqpi->rxq.databuffer_size = adapter->rx_rings[i].rx_buf_len;
62683ab5
GR
273 vqpi++;
274 }
275
fc86a970 276 adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
62683ab5
GR
277 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
278 (u8 *)vqci, len);
279 kfree(vqci);
62683ab5
GR
280}
281
282/**
283 * i40evf_enable_queues
284 * @adapter: adapter structure
285 *
286 * Request that the PF enable all of our queues.
287 **/
288void i40evf_enable_queues(struct i40evf_adapter *adapter)
289{
290 struct i40e_virtchnl_queue_select vqs;
291
292 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
293 /* bail because we already have a command pending */
fb43201f
SN
294 dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n",
295 adapter->current_op);
62683ab5
GR
296 return;
297 }
298 adapter->current_op = I40E_VIRTCHNL_OP_ENABLE_QUEUES;
299 vqs.vsi_id = adapter->vsi_res->vsi_id;
41a1d04b 300 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
62683ab5 301 vqs.rx_queues = vqs.tx_queues;
62683ab5 302 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES;
fc86a970
MW
303 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
304 (u8 *)&vqs, sizeof(vqs));
62683ab5
GR
305}
306
307/**
308 * i40evf_disable_queues
309 * @adapter: adapter structure
310 *
311 * Request that the PF disable all of our queues.
312 **/
313void i40evf_disable_queues(struct i40evf_adapter *adapter)
314{
315 struct i40e_virtchnl_queue_select vqs;
316
317 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
318 /* bail because we already have a command pending */
fb43201f
SN
319 dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
320 adapter->current_op);
62683ab5
GR
321 return;
322 }
323 adapter->current_op = I40E_VIRTCHNL_OP_DISABLE_QUEUES;
324 vqs.vsi_id = adapter->vsi_res->vsi_id;
41a1d04b 325 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
62683ab5 326 vqs.rx_queues = vqs.tx_queues;
62683ab5 327 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES;
fc86a970
MW
328 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
329 (u8 *)&vqs, sizeof(vqs));
62683ab5
GR
330}
331
332/**
333 * i40evf_map_queues
334 * @adapter: adapter structure
335 *
336 * Request that the PF map queues to interrupt vectors. Misc causes, including
337 * admin queue, are always mapped to vector 0.
338 **/
339void i40evf_map_queues(struct i40evf_adapter *adapter)
340{
341 struct i40e_virtchnl_irq_map_info *vimi;
342 int v_idx, q_vectors, len;
343 struct i40e_q_vector *q_vector;
344
345 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
346 /* bail because we already have a command pending */
fb43201f
SN
347 dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
348 adapter->current_op);
62683ab5
GR
349 return;
350 }
351 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP;
352
353 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
354
355 len = sizeof(struct i40e_virtchnl_irq_map_info) +
356 (adapter->num_msix_vectors *
357 sizeof(struct i40e_virtchnl_vector_map));
a85088d8 358 vimi = kzalloc(len, GFP_KERNEL);
249c8b8d 359 if (!vimi)
62683ab5 360 return;
62683ab5
GR
361
362 vimi->num_vectors = adapter->num_msix_vectors;
363 /* Queue vectors first */
364 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
7d96ba1a 365 q_vector = adapter->q_vectors + v_idx;
62683ab5
GR
366 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
367 vimi->vecmap[v_idx].vector_id = v_idx + NONQ_VECS;
368 vimi->vecmap[v_idx].txq_map = q_vector->ring_mask;
369 vimi->vecmap[v_idx].rxq_map = q_vector->ring_mask;
370 }
371 /* Misc vector last - this is only for AdminQ messages */
372 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
373 vimi->vecmap[v_idx].vector_id = 0;
374 vimi->vecmap[v_idx].txq_map = 0;
375 vimi->vecmap[v_idx].rxq_map = 0;
376
fc86a970 377 adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS;
62683ab5
GR
378 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
379 (u8 *)vimi, len);
380 kfree(vimi);
62683ab5
GR
381}
382
383/**
384 * i40evf_add_ether_addrs
385 * @adapter: adapter structure
386 * @addrs: the MAC address filters to add (contiguous)
387 * @count: number of filters
388 *
389 * Request that the PF add one or more addresses to our filters.
390 **/
391void i40evf_add_ether_addrs(struct i40evf_adapter *adapter)
392{
393 struct i40e_virtchnl_ether_addr_list *veal;
394 int len, i = 0, count = 0;
395 struct i40evf_mac_filter *f;
1418c345 396 bool more = false;
62683ab5
GR
397
398 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
399 /* bail because we already have a command pending */
fb43201f
SN
400 dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
401 adapter->current_op);
62683ab5
GR
402 return;
403 }
404 list_for_each_entry(f, &adapter->mac_filter_list, list) {
405 if (f->add)
406 count++;
407 }
408 if (!count) {
409 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
410 return;
411 }
412 adapter->current_op = I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS;
413
414 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
415 (count * sizeof(struct i40e_virtchnl_ether_addr));
416 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
fb43201f 417 dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
62683ab5
GR
418 count = (I40EVF_MAX_AQ_BUF_SIZE -
419 sizeof(struct i40e_virtchnl_ether_addr_list)) /
420 sizeof(struct i40e_virtchnl_ether_addr);
1418c345
MW
421 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
422 (count * sizeof(struct i40e_virtchnl_ether_addr));
423 more = true;
62683ab5
GR
424 }
425
a85088d8 426 veal = kzalloc(len, GFP_KERNEL);
249c8b8d 427 if (!veal)
62683ab5 428 return;
249c8b8d 429
62683ab5
GR
430 veal->vsi_id = adapter->vsi_res->vsi_id;
431 veal->num_elements = count;
432 list_for_each_entry(f, &adapter->mac_filter_list, list) {
433 if (f->add) {
9a173901 434 ether_addr_copy(veal->list[i].addr, f->macaddr);
62683ab5
GR
435 i++;
436 f->add = false;
437 }
438 }
1418c345
MW
439 if (!more)
440 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
62683ab5
GR
441 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
442 (u8 *)veal, len);
443 kfree(veal);
62683ab5
GR
444}
445
446/**
447 * i40evf_del_ether_addrs
448 * @adapter: adapter structure
449 * @addrs: the MAC address filters to remove (contiguous)
450 * @count: number of filtes
451 *
452 * Request that the PF remove one or more addresses from our filters.
453 **/
454void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
455{
456 struct i40e_virtchnl_ether_addr_list *veal;
457 struct i40evf_mac_filter *f, *ftmp;
458 int len, i = 0, count = 0;
1418c345 459 bool more = false;
62683ab5
GR
460
461 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
462 /* bail because we already have a command pending */
fb43201f
SN
463 dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
464 adapter->current_op);
62683ab5
GR
465 return;
466 }
467 list_for_each_entry(f, &adapter->mac_filter_list, list) {
468 if (f->remove)
469 count++;
470 }
471 if (!count) {
472 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
473 return;
474 }
475 adapter->current_op = I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS;
476
477 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
478 (count * sizeof(struct i40e_virtchnl_ether_addr));
479 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
fb43201f 480 dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
62683ab5
GR
481 count = (I40EVF_MAX_AQ_BUF_SIZE -
482 sizeof(struct i40e_virtchnl_ether_addr_list)) /
483 sizeof(struct i40e_virtchnl_ether_addr);
1418c345
MW
484 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
485 (count * sizeof(struct i40e_virtchnl_ether_addr));
486 more = true;
62683ab5 487 }
a85088d8 488 veal = kzalloc(len, GFP_KERNEL);
249c8b8d 489 if (!veal)
62683ab5 490 return;
249c8b8d 491
62683ab5
GR
492 veal->vsi_id = adapter->vsi_res->vsi_id;
493 veal->num_elements = count;
494 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
495 if (f->remove) {
9a173901 496 ether_addr_copy(veal->list[i].addr, f->macaddr);
62683ab5
GR
497 i++;
498 list_del(&f->list);
499 kfree(f);
500 }
501 }
1418c345
MW
502 if (!more)
503 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
62683ab5
GR
504 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
505 (u8 *)veal, len);
506 kfree(veal);
62683ab5
GR
507}
508
509/**
510 * i40evf_add_vlans
511 * @adapter: adapter structure
512 * @vlans: the VLANs to add
513 * @count: number of VLANs
514 *
515 * Request that the PF add one or more VLAN filters to our VSI.
516 **/
517void i40evf_add_vlans(struct i40evf_adapter *adapter)
518{
519 struct i40e_virtchnl_vlan_filter_list *vvfl;
520 int len, i = 0, count = 0;
521 struct i40evf_vlan_filter *f;
1418c345 522 bool more = false;
62683ab5
GR
523
524 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
525 /* bail because we already have a command pending */
fb43201f
SN
526 dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
527 adapter->current_op);
62683ab5
GR
528 return;
529 }
530
531 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
532 if (f->add)
533 count++;
534 }
535 if (!count) {
536 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
537 return;
538 }
539 adapter->current_op = I40E_VIRTCHNL_OP_ADD_VLAN;
540
541 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
542 (count * sizeof(u16));
543 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
fb43201f 544 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
62683ab5
GR
545 count = (I40EVF_MAX_AQ_BUF_SIZE -
546 sizeof(struct i40e_virtchnl_vlan_filter_list)) /
547 sizeof(u16);
1418c345
MW
548 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
549 (count * sizeof(u16));
550 more = true;
62683ab5 551 }
a85088d8 552 vvfl = kzalloc(len, GFP_KERNEL);
249c8b8d 553 if (!vvfl)
62683ab5 554 return;
249c8b8d 555
62683ab5
GR
556 vvfl->vsi_id = adapter->vsi_res->vsi_id;
557 vvfl->num_elements = count;
558 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
559 if (f->add) {
560 vvfl->vlan_id[i] = f->vlan;
561 i++;
562 f->add = false;
563 }
564 }
1418c345
MW
565 if (!more)
566 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
fc86a970
MW
567 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
568 kfree(vvfl);
62683ab5
GR
569}
570
571/**
572 * i40evf_del_vlans
573 * @adapter: adapter structure
574 * @vlans: the VLANs to remove
575 * @count: number of VLANs
576 *
577 * Request that the PF remove one or more VLAN filters from our VSI.
578 **/
579void i40evf_del_vlans(struct i40evf_adapter *adapter)
580{
581 struct i40e_virtchnl_vlan_filter_list *vvfl;
582 struct i40evf_vlan_filter *f, *ftmp;
583 int len, i = 0, count = 0;
1418c345 584 bool more = false;
62683ab5
GR
585
586 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
587 /* bail because we already have a command pending */
fb43201f
SN
588 dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
589 adapter->current_op);
62683ab5
GR
590 return;
591 }
592
593 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
594 if (f->remove)
595 count++;
596 }
597 if (!count) {
598 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
599 return;
600 }
601 adapter->current_op = I40E_VIRTCHNL_OP_DEL_VLAN;
602
603 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
604 (count * sizeof(u16));
605 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
fb43201f 606 dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
62683ab5
GR
607 count = (I40EVF_MAX_AQ_BUF_SIZE -
608 sizeof(struct i40e_virtchnl_vlan_filter_list)) /
609 sizeof(u16);
1418c345
MW
610 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
611 (count * sizeof(u16));
612 more = true;
62683ab5 613 }
a85088d8 614 vvfl = kzalloc(len, GFP_KERNEL);
249c8b8d 615 if (!vvfl)
62683ab5 616 return;
249c8b8d 617
62683ab5
GR
618 vvfl->vsi_id = adapter->vsi_res->vsi_id;
619 vvfl->num_elements = count;
620 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
621 if (f->remove) {
622 vvfl->vlan_id[i] = f->vlan;
623 i++;
624 list_del(&f->list);
625 kfree(f);
626 }
627 }
1418c345
MW
628 if (!more)
629 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
fc86a970
MW
630 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
631 kfree(vvfl);
62683ab5
GR
632}
633
634/**
635 * i40evf_set_promiscuous
636 * @adapter: adapter structure
637 * @flags: bitmask to control unicast/multicast promiscuous.
638 *
639 * Request that the PF enable promiscuous mode for our VSI.
640 **/
641void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
642{
643 struct i40e_virtchnl_promisc_info vpi;
f42a5c74 644 int promisc_all;
62683ab5
GR
645
646 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
647 /* bail because we already have a command pending */
fb43201f
SN
648 dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
649 adapter->current_op);
62683ab5
GR
650 return;
651 }
47d34839 652
f42a5c74
ASJ
653 promisc_all = I40E_FLAG_VF_UNICAST_PROMISC |
654 I40E_FLAG_VF_MULTICAST_PROMISC;
655 if ((flags & promisc_all) == promisc_all) {
47d34839
ASJ
656 adapter->flags |= I40EVF_FLAG_PROMISC_ON;
657 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_PROMISC;
658 dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
f42a5c74
ASJ
659 }
660
661 if (flags & I40E_FLAG_VF_MULTICAST_PROMISC) {
662 adapter->flags |= I40EVF_FLAG_ALLMULTI_ON;
663 adapter->aq_required &= ~I40EVF_FLAG_AQ_REQUEST_ALLMULTI;
664 dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
665 }
666
667 if (!flags) {
47d34839
ASJ
668 adapter->flags &= ~I40EVF_FLAG_PROMISC_ON;
669 adapter->aq_required &= ~I40EVF_FLAG_AQ_RELEASE_PROMISC;
670 dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
671 }
672
62683ab5
GR
673 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
674 vpi.vsi_id = adapter->vsi_res->vsi_id;
675 vpi.flags = flags;
676 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
677 (u8 *)&vpi, sizeof(vpi));
678}
679
680/**
681 * i40evf_request_stats
682 * @adapter: adapter structure
683 *
684 * Request VSI statistics from PF.
685 **/
686void i40evf_request_stats(struct i40evf_adapter *adapter)
687{
688 struct i40e_virtchnl_queue_select vqs;
75a64435 689
62683ab5
GR
690 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
691 /* no error message, this isn't crucial */
692 return;
693 }
694 adapter->current_op = I40E_VIRTCHNL_OP_GET_STATS;
695 vqs.vsi_id = adapter->vsi_res->vsi_id;
696 /* queue maps are ignored for this message - only the vsi is used */
697 if (i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_STATS,
698 (u8 *)&vqs, sizeof(vqs)))
699 /* if the request failed, don't lock out others */
700 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
701}
43a3d9ba
MW
702
703/**
704 * i40evf_get_hena
705 * @adapter: adapter structure
706 *
707 * Request hash enable capabilities from PF
708 **/
709void i40evf_get_hena(struct i40evf_adapter *adapter)
710{
711 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
712 /* bail because we already have a command pending */
713 dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
714 adapter->current_op);
715 return;
716 }
717 adapter->current_op = I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS;
718 adapter->aq_required &= ~I40EVF_FLAG_AQ_GET_HENA;
719 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS,
720 NULL, 0);
721}
722
723/**
724 * i40evf_set_hena
725 * @adapter: adapter structure
726 *
727 * Request the PF to set our RSS hash capabilities
728 **/
729void i40evf_set_hena(struct i40evf_adapter *adapter)
730{
731 struct i40e_virtchnl_rss_hena vrh;
732
733 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
734 /* bail because we already have a command pending */
735 dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
736 adapter->current_op);
737 return;
738 }
739 vrh.hena = adapter->hena;
740 adapter->current_op = I40E_VIRTCHNL_OP_SET_RSS_HENA;
741 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_HENA;
742 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_SET_RSS_HENA,
743 (u8 *)&vrh, sizeof(vrh));
744}
745
746/**
747 * i40evf_set_rss_key
748 * @adapter: adapter structure
749 *
750 * Request the PF to set our RSS hash key
751 **/
752void i40evf_set_rss_key(struct i40evf_adapter *adapter)
753{
754 struct i40e_virtchnl_rss_key *vrk;
755 int len;
756
757 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
758 /* bail because we already have a command pending */
759 dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
760 adapter->current_op);
761 return;
762 }
763 len = sizeof(struct i40e_virtchnl_rss_key) +
764 (adapter->rss_key_size * sizeof(u8)) - 1;
765 vrk = kzalloc(len, GFP_KERNEL);
766 if (!vrk)
767 return;
768 vrk->vsi_id = adapter->vsi.id;
769 vrk->key_len = adapter->rss_key_size;
770 memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
771
772 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_RSS_KEY;
773 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_KEY;
774 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_RSS_KEY,
775 (u8 *)vrk, len);
776 kfree(vrk);
777}
778
779/**
780 * i40evf_set_rss_lut
781 * @adapter: adapter structure
782 *
783 * Request the PF to set our RSS lookup table
784 **/
785void i40evf_set_rss_lut(struct i40evf_adapter *adapter)
786{
787 struct i40e_virtchnl_rss_lut *vrl;
788 int len;
789
790 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
791 /* bail because we already have a command pending */
792 dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
793 adapter->current_op);
794 return;
795 }
796 len = sizeof(struct i40e_virtchnl_rss_lut) +
797 (adapter->rss_lut_size * sizeof(u8)) - 1;
798 vrl = kzalloc(len, GFP_KERNEL);
799 if (!vrl)
800 return;
801 vrl->vsi_id = adapter->vsi.id;
802 vrl->lut_entries = adapter->rss_lut_size;
803 memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
804 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_RSS_LUT;
805 adapter->aq_required &= ~I40EVF_FLAG_AQ_SET_RSS_LUT;
806 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_RSS_LUT,
807 (u8 *)vrl, len);
808 kfree(vrl);
809}
810
625777e3
MW
811/**
812 * i40evf_request_reset
813 * @adapter: adapter structure
814 *
815 * Request that the PF reset this VF. No response is expected.
816 **/
817void i40evf_request_reset(struct i40evf_adapter *adapter)
818{
819 /* Don't check CURRENT_OP - this is always higher priority */
820 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_RESET_VF, NULL, 0);
821 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
822}
62683ab5
GR
823
824/**
825 * i40evf_virtchnl_completion
826 * @adapter: adapter structure
827 * @v_opcode: opcode sent by PF
828 * @v_retval: retval sent by PF
829 * @msg: message sent by PF
830 * @msglen: message length
831 *
832 * Asynchronous completion function for admin queue messages. Rather than busy
833 * wait, we fire off our requests and assume that no errors will be returned.
834 * This function handles the reply messages.
835 **/
836void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
837 enum i40e_virtchnl_ops v_opcode,
838 i40e_status v_retval,
839 u8 *msg, u16 msglen)
840{
841 struct net_device *netdev = adapter->netdev;
842
843 if (v_opcode == I40E_VIRTCHNL_OP_EVENT) {
844 struct i40e_virtchnl_pf_event *vpe =
845 (struct i40e_virtchnl_pf_event *)msg;
846 switch (vpe->event) {
847 case I40E_VIRTCHNL_EVENT_LINK_CHANGE:
848 adapter->link_up =
849 vpe->event_data.link_event.link_status;
850 if (adapter->link_up && !netif_carrier_ok(netdev)) {
851 dev_info(&adapter->pdev->dev, "NIC Link is Up\n");
852 netif_carrier_on(netdev);
853 netif_tx_wake_all_queues(netdev);
854 } else if (!adapter->link_up) {
855 dev_info(&adapter->pdev->dev, "NIC Link is Down\n");
856 netif_carrier_off(netdev);
857 netif_tx_stop_all_queues(netdev);
858 }
859 break;
860 case I40E_VIRTCHNL_EVENT_RESET_IMPENDING:
ef8693eb
MW
861 dev_info(&adapter->pdev->dev, "PF reset warning received\n");
862 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
863 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
864 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
865 schedule_work(&adapter->reset_task);
866 }
62683ab5
GR
867 break;
868 default:
fb43201f
SN
869 dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
870 vpe->event);
62683ab5 871 break;
62683ab5
GR
872 }
873 return;
874 }
62683ab5 875 if (v_retval) {
8d8f2295
MW
876 switch (v_opcode) {
877 case I40E_VIRTCHNL_OP_ADD_VLAN:
878 dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
879 i40evf_stat_str(&adapter->hw, v_retval));
880 break;
881 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
882 dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
883 i40evf_stat_str(&adapter->hw, v_retval));
884 break;
885 case I40E_VIRTCHNL_OP_DEL_VLAN:
886 dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
887 i40evf_stat_str(&adapter->hw, v_retval));
888 break;
889 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
890 dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
891 i40evf_stat_str(&adapter->hw, v_retval));
892 break;
893 default:
894 dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
895 v_retval,
896 i40evf_stat_str(&adapter->hw, v_retval),
897 v_opcode);
898 }
62683ab5
GR
899 }
900 switch (v_opcode) {
901 case I40E_VIRTCHNL_OP_GET_STATS: {
902 struct i40e_eth_stats *stats =
903 (struct i40e_eth_stats *)msg;
904 adapter->net_stats.rx_packets = stats->rx_unicast +
905 stats->rx_multicast +
906 stats->rx_broadcast;
907 adapter->net_stats.tx_packets = stats->tx_unicast +
908 stats->tx_multicast +
909 stats->tx_broadcast;
910 adapter->net_stats.rx_bytes = stats->rx_bytes;
911 adapter->net_stats.tx_bytes = stats->tx_bytes;
62683ab5 912 adapter->net_stats.tx_errors = stats->tx_errors;
03da6f6a 913 adapter->net_stats.rx_dropped = stats->rx_discards;
62683ab5
GR
914 adapter->net_stats.tx_dropped = stats->tx_discards;
915 adapter->current_stats = *stats;
916 }
917 break;
e6d038de
MW
918 case I40E_VIRTCHNL_OP_GET_VF_RESOURCES: {
919 u16 len = sizeof(struct i40e_virtchnl_vf_resource) +
920 I40E_MAX_VF_VSI *
921 sizeof(struct i40e_virtchnl_vsi_resource);
922 memcpy(adapter->vf_res, msg, min(msglen, len));
923 i40e_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
8552d854
MW
924 /* restore current mac address */
925 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
e6d038de
MW
926 i40evf_process_config(adapter);
927 }
928 break;
62683ab5 929 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
62683ab5
GR
930 /* enable transmits */
931 i40evf_irq_enable(adapter, true);
932 netif_tx_start_all_queues(adapter->netdev);
933 netif_carrier_on(adapter->netdev);
934 break;
935 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
e284fc88
MW
936 i40evf_free_all_tx_resources(adapter);
937 i40evf_free_all_rx_resources(adapter);
209dc4da
MW
938 if (adapter->state == __I40EVF_DOWN_PENDING)
939 adapter->state = __I40EVF_DOWN;
62683ab5 940 break;
ed636960 941 case I40E_VIRTCHNL_OP_VERSION:
62683ab5 942 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
ed636960
MW
943 /* Don't display an error if we get these out of sequence.
944 * If the firmware needed to get kicked, we'll get these and
945 * it's no problem.
946 */
947 if (v_opcode != adapter->current_op)
948 return;
62683ab5 949 break;
43a3d9ba
MW
950 case I40E_VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
951 struct i40e_virtchnl_rss_hena *vrh =
952 (struct i40e_virtchnl_rss_hena *)msg;
953 if (msglen == sizeof(*vrh))
954 adapter->hena = vrh->hena;
955 else
956 dev_warn(&adapter->pdev->dev,
957 "Invalid message %d from PF\n", v_opcode);
958 }
959 break;
62683ab5 960 default:
ed636960
MW
961 if (v_opcode != adapter->current_op)
962 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
963 adapter->current_op, v_opcode);
62683ab5
GR
964 break;
965 } /* switch v_opcode */
966 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
967}
This page took 0.221665 seconds and 5 git commands to generate.