i40e/i40evf: Bump build version
[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)
54 dev_err(&adapter->pdev->dev, "Unable to send opcode %d to PF, error %d, aq status %d\n",
55 op, err, hw->aq.asq_last_status);
56 return err;
57}
58
59/**
60 * i40evf_send_api_ver
61 * @adapter: adapter structure
62 *
63 * Send API version admin queue message to the PF. The reply is not checked
64 * in this function. Returns 0 if the message was successfully
65 * sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
66 **/
67int i40evf_send_api_ver(struct i40evf_adapter *adapter)
68{
69 struct i40e_virtchnl_version_info vvi;
70
71 vvi.major = I40E_VIRTCHNL_VERSION_MAJOR;
72 vvi.minor = I40E_VIRTCHNL_VERSION_MINOR;
73
74 return i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_VERSION, (u8 *)&vvi,
75 sizeof(vvi));
76}
77
78/**
79 * i40evf_verify_api_ver
80 * @adapter: adapter structure
81 *
82 * Compare API versions with the PF. Must be called after admin queue is
83 * initialized. Returns 0 if API versions match, -EIO if
84 * they do not, or I40E_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty.
85 **/
86int i40evf_verify_api_ver(struct i40evf_adapter *adapter)
87{
88 struct i40e_virtchnl_version_info *pf_vvi;
89 struct i40e_hw *hw = &adapter->hw;
90 struct i40e_arq_event_info event;
91 i40e_status err;
92
93 event.msg_size = I40EVF_MAX_AQ_BUF_SIZE;
94 event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL);
95 if (!event.msg_buf) {
96 err = -ENOMEM;
97 goto out;
98 }
99
100 err = i40evf_clean_arq_element(hw, &event, NULL);
101 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK)
102 goto out_alloc;
103
104 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
105 if (err) {
106 err = -EIO;
107 goto out_alloc;
108 }
109
110 if ((enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high) !=
111 I40E_VIRTCHNL_OP_VERSION) {
112 err = -EIO;
113 goto out_alloc;
114 }
115
116 pf_vvi = (struct i40e_virtchnl_version_info *)event.msg_buf;
117 if ((pf_vvi->major != I40E_VIRTCHNL_VERSION_MAJOR) ||
118 (pf_vvi->minor != I40E_VIRTCHNL_VERSION_MINOR))
119 err = -EIO;
120
121out_alloc:
122 kfree(event.msg_buf);
123out:
124 return err;
125}
126
127/**
128 * i40evf_send_vf_config_msg
129 * @adapter: adapter structure
130 *
131 * Send VF configuration request admin queue message to the PF. The reply
132 * is not checked in this function. Returns 0 if the message was
133 * successfully sent, or one of the I40E_ADMIN_QUEUE_ERROR_ statuses if not.
134 **/
135int i40evf_send_vf_config_msg(struct i40evf_adapter *adapter)
136{
137 return i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_VF_RESOURCES,
138 NULL, 0);
139}
140
141/**
142 * i40evf_get_vf_config
143 * @hw: pointer to the hardware structure
144 * @len: length of buffer
145 *
146 * Get VF configuration from PF and populate hw structure. Must be called after
147 * admin queue is initialized. Busy waits until response is received from PF,
148 * with maximum timeout. Response from PF is returned in the buffer for further
149 * processing by the caller.
150 **/
151int i40evf_get_vf_config(struct i40evf_adapter *adapter)
152{
153 struct i40e_hw *hw = &adapter->hw;
154 struct i40e_arq_event_info event;
155 u16 len;
156 i40e_status err;
157
158 len = sizeof(struct i40e_virtchnl_vf_resource) +
159 I40E_MAX_VF_VSI * sizeof(struct i40e_virtchnl_vsi_resource);
160 event.msg_size = len;
161 event.msg_buf = kzalloc(event.msg_size, GFP_KERNEL);
162 if (!event.msg_buf) {
163 err = -ENOMEM;
164 goto out;
165 }
166
167 err = i40evf_clean_arq_element(hw, &event, NULL);
168 if (err == I40E_ERR_ADMIN_QUEUE_NO_WORK)
169 goto out_alloc;
170
171 err = (i40e_status)le32_to_cpu(event.desc.cookie_low);
172 if (err) {
173 dev_err(&adapter->pdev->dev,
174 "%s: Error returned from PF, %d, %d\n", __func__,
175 le32_to_cpu(event.desc.cookie_high),
176 le32_to_cpu(event.desc.cookie_low));
177 err = -EIO;
178 goto out_alloc;
179 }
180
181 if ((enum i40e_virtchnl_ops)le32_to_cpu(event.desc.cookie_high) !=
182 I40E_VIRTCHNL_OP_GET_VF_RESOURCES) {
183 dev_err(&adapter->pdev->dev,
184 "%s: Invalid response from PF, %d, %d\n", __func__,
185 le32_to_cpu(event.desc.cookie_high),
186 le32_to_cpu(event.desc.cookie_low));
187 err = -EIO;
188 goto out_alloc;
189 }
190 memcpy(adapter->vf_res, event.msg_buf, min(event.msg_size, len));
191
192 i40e_vf_parse_hw_config(hw, adapter->vf_res);
193out_alloc:
194 kfree(event.msg_buf);
195out:
196 return err;
197}
198
199/**
200 * i40evf_configure_queues
201 * @adapter: adapter structure
202 *
203 * Request that the PF set up our (previously allocated) queues.
204 **/
205void i40evf_configure_queues(struct i40evf_adapter *adapter)
206{
207 struct i40e_virtchnl_vsi_queue_config_info *vqci;
208 struct i40e_virtchnl_queue_pair_info *vqpi;
209 int pairs = adapter->vsi_res->num_queue_pairs;
210 int i, len;
211
212 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
213 /* bail because we already have a command pending */
214 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
215 __func__, adapter->current_op);
216 return;
217 }
218 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES;
219 len = sizeof(struct i40e_virtchnl_vsi_queue_config_info) +
220 (sizeof(struct i40e_virtchnl_queue_pair_info) * pairs);
221 vqci = kzalloc(len, GFP_ATOMIC);
222 if (!vqci) {
223 dev_err(&adapter->pdev->dev, "%s: unable to allocate memory\n",
224 __func__);
225 return;
226 }
227 vqci->vsi_id = adapter->vsi_res->vsi_id;
228 vqci->num_queue_pairs = pairs;
229 vqpi = vqci->qpair;
230 /* Size check is not needed here - HW max is 16 queue pairs, and we
231 * can fit info for 31 of them into the AQ buffer before it overflows.
232 */
233 for (i = 0; i < pairs; i++) {
234 vqpi->txq.vsi_id = vqci->vsi_id;
235 vqpi->txq.queue_id = i;
236 vqpi->txq.ring_len = adapter->tx_rings[i]->count;
237 vqpi->txq.dma_ring_addr = adapter->tx_rings[i]->dma;
238
239 vqpi->rxq.vsi_id = vqci->vsi_id;
240 vqpi->rxq.queue_id = i;
241 vqpi->rxq.ring_len = adapter->rx_rings[i]->count;
242 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i]->dma;
243 vqpi->rxq.max_pkt_size = adapter->netdev->mtu
244 + ETH_HLEN + VLAN_HLEN + ETH_FCS_LEN;
245 vqpi->rxq.databuffer_size = adapter->rx_rings[i]->rx_buf_len;
246 vqpi++;
247 }
248
249 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES,
250 (u8 *)vqci, len);
251 kfree(vqci);
252 adapter->aq_pending |= I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
253 adapter->aq_required &= ~I40EVF_FLAG_AQ_CONFIGURE_QUEUES;
254}
255
256/**
257 * i40evf_enable_queues
258 * @adapter: adapter structure
259 *
260 * Request that the PF enable all of our queues.
261 **/
262void i40evf_enable_queues(struct i40evf_adapter *adapter)
263{
264 struct i40e_virtchnl_queue_select vqs;
265
266 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
267 /* bail because we already have a command pending */
268 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
269 __func__, adapter->current_op);
270 return;
271 }
272 adapter->current_op = I40E_VIRTCHNL_OP_ENABLE_QUEUES;
273 vqs.vsi_id = adapter->vsi_res->vsi_id;
274 vqs.tx_queues = (1 << adapter->vsi_res->num_queue_pairs) - 1;
275 vqs.rx_queues = vqs.tx_queues;
276 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ENABLE_QUEUES,
277 (u8 *)&vqs, sizeof(vqs));
278 adapter->aq_pending |= I40EVF_FLAG_AQ_ENABLE_QUEUES;
279 adapter->aq_required &= ~I40EVF_FLAG_AQ_ENABLE_QUEUES;
280}
281
282/**
283 * i40evf_disable_queues
284 * @adapter: adapter structure
285 *
286 * Request that the PF disable all of our queues.
287 **/
288void i40evf_disable_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 */
294 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
295 __func__, adapter->current_op);
296 return;
297 }
298 adapter->current_op = I40E_VIRTCHNL_OP_DISABLE_QUEUES;
299 vqs.vsi_id = adapter->vsi_res->vsi_id;
300 vqs.tx_queues = (1 << adapter->vsi_res->num_queue_pairs) - 1;
301 vqs.rx_queues = vqs.tx_queues;
302 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DISABLE_QUEUES,
303 (u8 *)&vqs, sizeof(vqs));
304 adapter->aq_pending |= I40EVF_FLAG_AQ_DISABLE_QUEUES;
305 adapter->aq_required &= ~I40EVF_FLAG_AQ_DISABLE_QUEUES;
306}
307
308/**
309 * i40evf_map_queues
310 * @adapter: adapter structure
311 *
312 * Request that the PF map queues to interrupt vectors. Misc causes, including
313 * admin queue, are always mapped to vector 0.
314 **/
315void i40evf_map_queues(struct i40evf_adapter *adapter)
316{
317 struct i40e_virtchnl_irq_map_info *vimi;
318 int v_idx, q_vectors, len;
319 struct i40e_q_vector *q_vector;
320
321 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
322 /* bail because we already have a command pending */
323 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
324 __func__, adapter->current_op);
325 return;
326 }
327 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP;
328
329 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
330
331 len = sizeof(struct i40e_virtchnl_irq_map_info) +
332 (adapter->num_msix_vectors *
333 sizeof(struct i40e_virtchnl_vector_map));
334 vimi = kzalloc(len, GFP_ATOMIC);
335 if (!vimi) {
336 dev_err(&adapter->pdev->dev, "%s: unable to allocate memory\n",
337 __func__);
338 return;
339 }
340
341 vimi->num_vectors = adapter->num_msix_vectors;
342 /* Queue vectors first */
343 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
344 q_vector = adapter->q_vector[v_idx];
345 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
346 vimi->vecmap[v_idx].vector_id = v_idx + NONQ_VECS;
347 vimi->vecmap[v_idx].txq_map = q_vector->ring_mask;
348 vimi->vecmap[v_idx].rxq_map = q_vector->ring_mask;
349 }
350 /* Misc vector last - this is only for AdminQ messages */
351 vimi->vecmap[v_idx].vsi_id = adapter->vsi_res->vsi_id;
352 vimi->vecmap[v_idx].vector_id = 0;
353 vimi->vecmap[v_idx].txq_map = 0;
354 vimi->vecmap[v_idx].rxq_map = 0;
355
356 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP,
357 (u8 *)vimi, len);
358 kfree(vimi);
359 adapter->aq_pending |= I40EVF_FLAG_AQ_MAP_VECTORS;
360 adapter->aq_required &= ~I40EVF_FLAG_AQ_MAP_VECTORS;
361}
362
363/**
364 * i40evf_add_ether_addrs
365 * @adapter: adapter structure
366 * @addrs: the MAC address filters to add (contiguous)
367 * @count: number of filters
368 *
369 * Request that the PF add one or more addresses to our filters.
370 **/
371void i40evf_add_ether_addrs(struct i40evf_adapter *adapter)
372{
373 struct i40e_virtchnl_ether_addr_list *veal;
374 int len, i = 0, count = 0;
375 struct i40evf_mac_filter *f;
376
377 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
378 /* bail because we already have a command pending */
379 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
380 __func__, adapter->current_op);
381 return;
382 }
383 list_for_each_entry(f, &adapter->mac_filter_list, list) {
384 if (f->add)
385 count++;
386 }
387 if (!count) {
388 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
389 return;
390 }
391 adapter->current_op = I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS;
392
393 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
394 (count * sizeof(struct i40e_virtchnl_ether_addr));
395 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
396 dev_warn(&adapter->pdev->dev, "%s: Too many MAC address changes in one request.\n",
397 __func__);
398 count = (I40EVF_MAX_AQ_BUF_SIZE -
399 sizeof(struct i40e_virtchnl_ether_addr_list)) /
400 sizeof(struct i40e_virtchnl_ether_addr);
401 len = I40EVF_MAX_AQ_BUF_SIZE;
402 }
403
404 veal = kzalloc(len, GFP_ATOMIC);
405 if (!veal) {
406 dev_err(&adapter->pdev->dev, "%s: unable to allocate memory\n",
407 __func__);
408 return;
409 }
410 veal->vsi_id = adapter->vsi_res->vsi_id;
411 veal->num_elements = count;
412 list_for_each_entry(f, &adapter->mac_filter_list, list) {
413 if (f->add) {
414 memcpy(veal->list[i].addr, f->macaddr, ETH_ALEN);
415 i++;
416 f->add = false;
417 }
418 }
419 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS,
420 (u8 *)veal, len);
421 kfree(veal);
422 adapter->aq_pending |= I40EVF_FLAG_AQ_ADD_MAC_FILTER;
423 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_MAC_FILTER;
424
425}
426
427/**
428 * i40evf_del_ether_addrs
429 * @adapter: adapter structure
430 * @addrs: the MAC address filters to remove (contiguous)
431 * @count: number of filtes
432 *
433 * Request that the PF remove one or more addresses from our filters.
434 **/
435void i40evf_del_ether_addrs(struct i40evf_adapter *adapter)
436{
437 struct i40e_virtchnl_ether_addr_list *veal;
438 struct i40evf_mac_filter *f, *ftmp;
439 int len, i = 0, count = 0;
440
441 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
442 /* bail because we already have a command pending */
443 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
444 __func__, adapter->current_op);
445 return;
446 }
447 list_for_each_entry(f, &adapter->mac_filter_list, list) {
448 if (f->remove)
449 count++;
450 }
451 if (!count) {
452 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
453 return;
454 }
455 adapter->current_op = I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS;
456
457 len = sizeof(struct i40e_virtchnl_ether_addr_list) +
458 (count * sizeof(struct i40e_virtchnl_ether_addr));
459 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
460 dev_warn(&adapter->pdev->dev, "%s: Too many MAC address changes in one request.\n",
461 __func__);
462 count = (I40EVF_MAX_AQ_BUF_SIZE -
463 sizeof(struct i40e_virtchnl_ether_addr_list)) /
464 sizeof(struct i40e_virtchnl_ether_addr);
465 len = I40EVF_MAX_AQ_BUF_SIZE;
466 }
467 veal = kzalloc(len, GFP_ATOMIC);
468 if (!veal) {
469 dev_err(&adapter->pdev->dev, "%s: unable to allocate memory\n",
470 __func__);
471 return;
472 }
473 veal->vsi_id = adapter->vsi_res->vsi_id;
474 veal->num_elements = count;
475 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
476 if (f->remove) {
477 memcpy(veal->list[i].addr, f->macaddr, ETH_ALEN);
478 i++;
479 list_del(&f->list);
480 kfree(f);
481 }
482 }
483 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS,
484 (u8 *)veal, len);
485 kfree(veal);
486 adapter->aq_pending |= I40EVF_FLAG_AQ_DEL_MAC_FILTER;
487 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_MAC_FILTER;
488}
489
490/**
491 * i40evf_add_vlans
492 * @adapter: adapter structure
493 * @vlans: the VLANs to add
494 * @count: number of VLANs
495 *
496 * Request that the PF add one or more VLAN filters to our VSI.
497 **/
498void i40evf_add_vlans(struct i40evf_adapter *adapter)
499{
500 struct i40e_virtchnl_vlan_filter_list *vvfl;
501 int len, i = 0, count = 0;
502 struct i40evf_vlan_filter *f;
503
504 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
505 /* bail because we already have a command pending */
506 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
507 __func__, adapter->current_op);
508 return;
509 }
510
511 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
512 if (f->add)
513 count++;
514 }
515 if (!count) {
516 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
517 return;
518 }
519 adapter->current_op = I40E_VIRTCHNL_OP_ADD_VLAN;
520
521 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
522 (count * sizeof(u16));
523 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
524 dev_warn(&adapter->pdev->dev, "%s: Too many VLAN changes in one request.\n",
525 __func__);
526 count = (I40EVF_MAX_AQ_BUF_SIZE -
527 sizeof(struct i40e_virtchnl_vlan_filter_list)) /
528 sizeof(u16);
529 len = I40EVF_MAX_AQ_BUF_SIZE;
530 }
531 vvfl = kzalloc(len, GFP_ATOMIC);
532 if (!vvfl) {
533 dev_err(&adapter->pdev->dev, "%s: unable to allocate memory\n",
534 __func__);
535 return;
536 }
537 vvfl->vsi_id = adapter->vsi_res->vsi_id;
538 vvfl->num_elements = count;
539 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
540 if (f->add) {
541 vvfl->vlan_id[i] = f->vlan;
542 i++;
543 f->add = false;
544 }
545 }
546 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
547 kfree(vvfl);
548 adapter->aq_pending |= I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
549 adapter->aq_required &= ~I40EVF_FLAG_AQ_ADD_VLAN_FILTER;
550}
551
552/**
553 * i40evf_del_vlans
554 * @adapter: adapter structure
555 * @vlans: the VLANs to remove
556 * @count: number of VLANs
557 *
558 * Request that the PF remove one or more VLAN filters from our VSI.
559 **/
560void i40evf_del_vlans(struct i40evf_adapter *adapter)
561{
562 struct i40e_virtchnl_vlan_filter_list *vvfl;
563 struct i40evf_vlan_filter *f, *ftmp;
564 int len, i = 0, count = 0;
565
566 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
567 /* bail because we already have a command pending */
568 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
569 __func__, adapter->current_op);
570 return;
571 }
572
573 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
574 if (f->remove)
575 count++;
576 }
577 if (!count) {
578 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
579 return;
580 }
581 adapter->current_op = I40E_VIRTCHNL_OP_DEL_VLAN;
582
583 len = sizeof(struct i40e_virtchnl_vlan_filter_list) +
584 (count * sizeof(u16));
585 if (len > I40EVF_MAX_AQ_BUF_SIZE) {
586 dev_warn(&adapter->pdev->dev, "%s: Too many VLAN changes in one request.\n",
587 __func__);
588 count = (I40EVF_MAX_AQ_BUF_SIZE -
589 sizeof(struct i40e_virtchnl_vlan_filter_list)) /
590 sizeof(u16);
591 len = I40EVF_MAX_AQ_BUF_SIZE;
592 }
593 vvfl = kzalloc(len, GFP_ATOMIC);
594 if (!vvfl) {
595 dev_err(&adapter->pdev->dev, "%s: unable to allocate memory\n",
596 __func__);
597 return;
598 }
599 vvfl->vsi_id = adapter->vsi_res->vsi_id;
600 vvfl->num_elements = count;
601 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
602 if (f->remove) {
603 vvfl->vlan_id[i] = f->vlan;
604 i++;
605 list_del(&f->list);
606 kfree(f);
607 }
608 }
609 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
610 kfree(vvfl);
611 adapter->aq_pending |= I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
612 adapter->aq_required &= ~I40EVF_FLAG_AQ_DEL_VLAN_FILTER;
613}
614
615/**
616 * i40evf_set_promiscuous
617 * @adapter: adapter structure
618 * @flags: bitmask to control unicast/multicast promiscuous.
619 *
620 * Request that the PF enable promiscuous mode for our VSI.
621 **/
622void i40evf_set_promiscuous(struct i40evf_adapter *adapter, int flags)
623{
624 struct i40e_virtchnl_promisc_info vpi;
625
626 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
627 /* bail because we already have a command pending */
628 dev_err(&adapter->pdev->dev, "%s: command %d pending\n",
629 __func__, adapter->current_op);
630 return;
631 }
632 adapter->current_op = I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
633 vpi.vsi_id = adapter->vsi_res->vsi_id;
634 vpi.flags = flags;
635 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
636 (u8 *)&vpi, sizeof(vpi));
637}
638
639/**
640 * i40evf_request_stats
641 * @adapter: adapter structure
642 *
643 * Request VSI statistics from PF.
644 **/
645void i40evf_request_stats(struct i40evf_adapter *adapter)
646{
647 struct i40e_virtchnl_queue_select vqs;
648 if (adapter->current_op != I40E_VIRTCHNL_OP_UNKNOWN) {
649 /* no error message, this isn't crucial */
650 return;
651 }
652 adapter->current_op = I40E_VIRTCHNL_OP_GET_STATS;
653 vqs.vsi_id = adapter->vsi_res->vsi_id;
654 /* queue maps are ignored for this message - only the vsi is used */
655 if (i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_GET_STATS,
656 (u8 *)&vqs, sizeof(vqs)))
657 /* if the request failed, don't lock out others */
658 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
659}
625777e3
MW
660/**
661 * i40evf_request_reset
662 * @adapter: adapter structure
663 *
664 * Request that the PF reset this VF. No response is expected.
665 **/
666void i40evf_request_reset(struct i40evf_adapter *adapter)
667{
668 /* Don't check CURRENT_OP - this is always higher priority */
669 i40evf_send_pf_msg(adapter, I40E_VIRTCHNL_OP_RESET_VF, NULL, 0);
670 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
671}
62683ab5
GR
672
673/**
674 * i40evf_virtchnl_completion
675 * @adapter: adapter structure
676 * @v_opcode: opcode sent by PF
677 * @v_retval: retval sent by PF
678 * @msg: message sent by PF
679 * @msglen: message length
680 *
681 * Asynchronous completion function for admin queue messages. Rather than busy
682 * wait, we fire off our requests and assume that no errors will be returned.
683 * This function handles the reply messages.
684 **/
685void i40evf_virtchnl_completion(struct i40evf_adapter *adapter,
686 enum i40e_virtchnl_ops v_opcode,
687 i40e_status v_retval,
688 u8 *msg, u16 msglen)
689{
690 struct net_device *netdev = adapter->netdev;
691
692 if (v_opcode == I40E_VIRTCHNL_OP_EVENT) {
693 struct i40e_virtchnl_pf_event *vpe =
694 (struct i40e_virtchnl_pf_event *)msg;
695 switch (vpe->event) {
696 case I40E_VIRTCHNL_EVENT_LINK_CHANGE:
697 adapter->link_up =
698 vpe->event_data.link_event.link_status;
699 if (adapter->link_up && !netif_carrier_ok(netdev)) {
700 dev_info(&adapter->pdev->dev, "NIC Link is Up\n");
701 netif_carrier_on(netdev);
702 netif_tx_wake_all_queues(netdev);
703 } else if (!adapter->link_up) {
704 dev_info(&adapter->pdev->dev, "NIC Link is Down\n");
705 netif_carrier_off(netdev);
706 netif_tx_stop_all_queues(netdev);
707 }
708 break;
709 case I40E_VIRTCHNL_EVENT_RESET_IMPENDING:
ef8693eb
MW
710 dev_info(&adapter->pdev->dev, "PF reset warning received\n");
711 if (!(adapter->flags & I40EVF_FLAG_RESET_PENDING)) {
712 adapter->flags |= I40EVF_FLAG_RESET_PENDING;
713 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
714 schedule_work(&adapter->reset_task);
715 }
62683ab5
GR
716 break;
717 default:
718 dev_err(&adapter->pdev->dev,
719 "%s: Unknown event %d from pf\n",
720 __func__, vpe->event);
721 break;
722
723 }
724 return;
725 }
726 if (v_opcode != adapter->current_op) {
727 dev_err(&adapter->pdev->dev, "%s: Pending op is %d, received %d.\n",
728 __func__, adapter->current_op, v_opcode);
729 /* We're probably completely screwed at this point, but clear
730 * the current op and try to carry on....
731 */
732 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
733 return;
734 }
735 if (v_retval) {
736 dev_err(&adapter->pdev->dev, "%s: PF returned error %d to our request %d!\n",
737 __func__, v_retval, v_opcode);
738 }
739 switch (v_opcode) {
740 case I40E_VIRTCHNL_OP_GET_STATS: {
741 struct i40e_eth_stats *stats =
742 (struct i40e_eth_stats *)msg;
743 adapter->net_stats.rx_packets = stats->rx_unicast +
744 stats->rx_multicast +
745 stats->rx_broadcast;
746 adapter->net_stats.tx_packets = stats->tx_unicast +
747 stats->tx_multicast +
748 stats->tx_broadcast;
749 adapter->net_stats.rx_bytes = stats->rx_bytes;
750 adapter->net_stats.tx_bytes = stats->tx_bytes;
62683ab5 751 adapter->net_stats.tx_errors = stats->tx_errors;
03da6f6a 752 adapter->net_stats.rx_dropped = stats->rx_discards;
62683ab5
GR
753 adapter->net_stats.tx_dropped = stats->tx_discards;
754 adapter->current_stats = *stats;
755 }
756 break;
757 case I40E_VIRTCHNL_OP_ADD_ETHER_ADDRESS:
758 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_ADD_MAC_FILTER);
759 break;
760 case I40E_VIRTCHNL_OP_DEL_ETHER_ADDRESS:
761 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_DEL_MAC_FILTER);
762 break;
763 case I40E_VIRTCHNL_OP_ADD_VLAN:
764 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_ADD_VLAN_FILTER);
765 break;
766 case I40E_VIRTCHNL_OP_DEL_VLAN:
767 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_DEL_VLAN_FILTER);
768 break;
769 case I40E_VIRTCHNL_OP_ENABLE_QUEUES:
770 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_ENABLE_QUEUES);
771 /* enable transmits */
772 i40evf_irq_enable(adapter, true);
773 netif_tx_start_all_queues(adapter->netdev);
774 netif_carrier_on(adapter->netdev);
775 break;
776 case I40E_VIRTCHNL_OP_DISABLE_QUEUES:
777 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_DISABLE_QUEUES);
778 break;
779 case I40E_VIRTCHNL_OP_CONFIG_VSI_QUEUES:
780 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_CONFIGURE_QUEUES);
781 break;
782 case I40E_VIRTCHNL_OP_CONFIG_IRQ_MAP:
783 adapter->aq_pending &= ~(I40EVF_FLAG_AQ_MAP_VECTORS);
784 break;
785 default:
786 dev_warn(&adapter->pdev->dev, "%s: Received unexpected message %d from PF.\n",
787 __func__, v_opcode);
788 break;
789 } /* switch v_opcode */
790 adapter->current_op = I40E_VIRTCHNL_OP_UNKNOWN;
791}
This page took 0.089774 seconds and 5 git commands to generate.