]> git.itanic.dy.fi Git - linux-stable/blob - drivers/net/ethernet/intel/iavf/iavf_virtchnl.c
iavf: Fix set max MTU size with port VLAN and jumbo frames
[linux-stable] / drivers / net / ethernet / intel / iavf / iavf_virtchnl.c
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 2013 - 2018 Intel Corporation. */
3
4 #include "iavf.h"
5 #include "iavf_prototype.h"
6 #include "iavf_client.h"
7
8 /* busy wait delay in msec */
9 #define IAVF_BUSY_WAIT_DELAY 10
10 #define IAVF_BUSY_WAIT_COUNT 50
11
12 /**
13  * iavf_send_pf_msg
14  * @adapter: adapter structure
15  * @op: virtual channel opcode
16  * @msg: pointer to message buffer
17  * @len: message length
18  *
19  * Send message to PF and print status if failure.
20  **/
21 static int iavf_send_pf_msg(struct iavf_adapter *adapter,
22                             enum virtchnl_ops op, u8 *msg, u16 len)
23 {
24         struct iavf_hw *hw = &adapter->hw;
25         enum iavf_status status;
26
27         if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED)
28                 return 0; /* nothing to see here, move along */
29
30         status = iavf_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL);
31         if (status)
32                 dev_dbg(&adapter->pdev->dev, "Unable to send opcode %d to PF, status %s, aq_err %s\n",
33                         op, iavf_stat_str(hw, status),
34                         iavf_aq_str(hw, hw->aq.asq_last_status));
35         return iavf_status_to_errno(status);
36 }
37
38 /**
39  * iavf_send_api_ver
40  * @adapter: adapter structure
41  *
42  * Send API version admin queue message to the PF. The reply is not checked
43  * in this function. Returns 0 if the message was successfully
44  * sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not.
45  **/
46 int iavf_send_api_ver(struct iavf_adapter *adapter)
47 {
48         struct virtchnl_version_info vvi;
49
50         vvi.major = VIRTCHNL_VERSION_MAJOR;
51         vvi.minor = VIRTCHNL_VERSION_MINOR;
52
53         return iavf_send_pf_msg(adapter, VIRTCHNL_OP_VERSION, (u8 *)&vvi,
54                                 sizeof(vvi));
55 }
56
57 /**
58  * iavf_poll_virtchnl_msg
59  * @hw: HW configuration structure
60  * @event: event to populate on success
61  * @op_to_poll: requested virtchnl op to poll for
62  *
63  * Initialize poll for virtchnl msg matching the requested_op. Returns 0
64  * if a message of the correct opcode is in the queue or an error code
65  * if no message matching the op code is waiting and other failures.
66  */
67 static int
68 iavf_poll_virtchnl_msg(struct iavf_hw *hw, struct iavf_arq_event_info *event,
69                        enum virtchnl_ops op_to_poll)
70 {
71         enum virtchnl_ops received_op;
72         enum iavf_status status;
73         u32 v_retval;
74
75         while (1) {
76                 /* When the AQ is empty, iavf_clean_arq_element will return
77                  * nonzero and this loop will terminate.
78                  */
79                 status = iavf_clean_arq_element(hw, event, NULL);
80                 if (status != IAVF_SUCCESS)
81                         return iavf_status_to_errno(status);
82                 received_op =
83                     (enum virtchnl_ops)le32_to_cpu(event->desc.cookie_high);
84                 if (op_to_poll == received_op)
85                         break;
86         }
87
88         v_retval = le32_to_cpu(event->desc.cookie_low);
89         return virtchnl_status_to_errno((enum virtchnl_status_code)v_retval);
90 }
91
92 /**
93  * iavf_verify_api_ver
94  * @adapter: adapter structure
95  *
96  * Compare API versions with the PF. Must be called after admin queue is
97  * initialized. Returns 0 if API versions match, -EIO if they do not,
98  * IAVF_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors
99  * from the firmware are propagated.
100  **/
101 int iavf_verify_api_ver(struct iavf_adapter *adapter)
102 {
103         struct iavf_arq_event_info event;
104         int err;
105
106         event.buf_len = IAVF_MAX_AQ_BUF_SIZE;
107         event.msg_buf = kzalloc(IAVF_MAX_AQ_BUF_SIZE, GFP_KERNEL);
108         if (!event.msg_buf)
109                 return -ENOMEM;
110
111         err = iavf_poll_virtchnl_msg(&adapter->hw, &event, VIRTCHNL_OP_VERSION);
112         if (!err) {
113                 struct virtchnl_version_info *pf_vvi =
114                         (struct virtchnl_version_info *)event.msg_buf;
115                 adapter->pf_version = *pf_vvi;
116
117                 if (pf_vvi->major > VIRTCHNL_VERSION_MAJOR ||
118                     (pf_vvi->major == VIRTCHNL_VERSION_MAJOR &&
119                      pf_vvi->minor > VIRTCHNL_VERSION_MINOR))
120                         err = -EIO;
121         }
122
123         kfree(event.msg_buf);
124
125         return err;
126 }
127
128 /**
129  * iavf_send_vf_config_msg
130  * @adapter: adapter structure
131  *
132  * Send VF configuration request admin queue message to the PF. The reply
133  * is not checked in this function. Returns 0 if the message was
134  * successfully sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not.
135  **/
136 int iavf_send_vf_config_msg(struct iavf_adapter *adapter)
137 {
138         u32 caps;
139
140         caps = VIRTCHNL_VF_OFFLOAD_L2 |
141                VIRTCHNL_VF_OFFLOAD_RSS_PF |
142                VIRTCHNL_VF_OFFLOAD_RSS_AQ |
143                VIRTCHNL_VF_OFFLOAD_RSS_REG |
144                VIRTCHNL_VF_OFFLOAD_VLAN |
145                VIRTCHNL_VF_OFFLOAD_WB_ON_ITR |
146                VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 |
147                VIRTCHNL_VF_OFFLOAD_ENCAP |
148                VIRTCHNL_VF_OFFLOAD_VLAN_V2 |
149                VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM |
150                VIRTCHNL_VF_OFFLOAD_REQ_QUEUES |
151                VIRTCHNL_VF_OFFLOAD_ADQ |
152                VIRTCHNL_VF_OFFLOAD_USO |
153                VIRTCHNL_VF_OFFLOAD_FDIR_PF |
154                VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF |
155                VIRTCHNL_VF_CAP_ADV_LINK_SPEED;
156
157         adapter->current_op = VIRTCHNL_OP_GET_VF_RESOURCES;
158         adapter->aq_required &= ~IAVF_FLAG_AQ_GET_CONFIG;
159         if (PF_IS_V11(adapter))
160                 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES,
161                                         (u8 *)&caps, sizeof(caps));
162         else
163                 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES,
164                                         NULL, 0);
165 }
166
167 int iavf_send_vf_offload_vlan_v2_msg(struct iavf_adapter *adapter)
168 {
169         adapter->aq_required &= ~IAVF_FLAG_AQ_GET_OFFLOAD_VLAN_V2_CAPS;
170
171         if (!VLAN_V2_ALLOWED(adapter))
172                 return -EOPNOTSUPP;
173
174         adapter->current_op = VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS;
175
176         return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS,
177                                 NULL, 0);
178 }
179
180 /**
181  * iavf_validate_num_queues
182  * @adapter: adapter structure
183  *
184  * Validate that the number of queues the PF has sent in
185  * VIRTCHNL_OP_GET_VF_RESOURCES is not larger than the VF can handle.
186  **/
187 static void iavf_validate_num_queues(struct iavf_adapter *adapter)
188 {
189         if (adapter->vf_res->num_queue_pairs > IAVF_MAX_REQ_QUEUES) {
190                 struct virtchnl_vsi_resource *vsi_res;
191                 int i;
192
193                 dev_info(&adapter->pdev->dev, "Received %d queues, but can only have a max of %d\n",
194                          adapter->vf_res->num_queue_pairs,
195                          IAVF_MAX_REQ_QUEUES);
196                 dev_info(&adapter->pdev->dev, "Fixing by reducing queues to %d\n",
197                          IAVF_MAX_REQ_QUEUES);
198                 adapter->vf_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES;
199                 for (i = 0; i < adapter->vf_res->num_vsis; i++) {
200                         vsi_res = &adapter->vf_res->vsi_res[i];
201                         vsi_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES;
202                 }
203         }
204 }
205
206 /**
207  * iavf_get_vf_config
208  * @adapter: private adapter structure
209  *
210  * Get VF configuration from PF and populate hw structure. Must be called after
211  * admin queue is initialized. Busy waits until response is received from PF,
212  * with maximum timeout. Response from PF is returned in the buffer for further
213  * processing by the caller.
214  **/
215 int iavf_get_vf_config(struct iavf_adapter *adapter)
216 {
217         struct iavf_hw *hw = &adapter->hw;
218         struct iavf_arq_event_info event;
219         u16 len;
220         int err;
221
222         len = sizeof(struct virtchnl_vf_resource) +
223                 IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
224         event.buf_len = len;
225         event.msg_buf = kzalloc(len, GFP_KERNEL);
226         if (!event.msg_buf)
227                 return -ENOMEM;
228
229         err = iavf_poll_virtchnl_msg(hw, &event, VIRTCHNL_OP_GET_VF_RESOURCES);
230         memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
231
232         /* some PFs send more queues than we should have so validate that
233          * we aren't getting too many queues
234          */
235         if (!err)
236                 iavf_validate_num_queues(adapter);
237         iavf_vf_parse_hw_config(hw, adapter->vf_res);
238
239         kfree(event.msg_buf);
240
241         return err;
242 }
243
244 int iavf_get_vf_vlan_v2_caps(struct iavf_adapter *adapter)
245 {
246         struct iavf_arq_event_info event;
247         int err;
248         u16 len;
249
250         len = sizeof(struct virtchnl_vlan_caps);
251         event.buf_len = len;
252         event.msg_buf = kzalloc(len, GFP_KERNEL);
253         if (!event.msg_buf)
254                 return -ENOMEM;
255
256         err = iavf_poll_virtchnl_msg(&adapter->hw, &event,
257                                      VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS);
258         if (!err)
259                 memcpy(&adapter->vlan_v2_caps, event.msg_buf,
260                        min(event.msg_len, len));
261
262         kfree(event.msg_buf);
263
264         return err;
265 }
266
267 /**
268  * iavf_configure_queues
269  * @adapter: adapter structure
270  *
271  * Request that the PF set up our (previously allocated) queues.
272  **/
273 void iavf_configure_queues(struct iavf_adapter *adapter)
274 {
275         struct virtchnl_vsi_queue_config_info *vqci;
276         int i, max_frame = adapter->vf_res->max_mtu;
277         int pairs = adapter->num_active_queues;
278         struct virtchnl_queue_pair_info *vqpi;
279         size_t len;
280
281         if (max_frame > IAVF_MAX_RXBUFFER || !max_frame)
282                 max_frame = IAVF_MAX_RXBUFFER;
283
284         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
285                 /* bail because we already have a command pending */
286                 dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
287                         adapter->current_op);
288                 return;
289         }
290         adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
291         len = struct_size(vqci, qpair, pairs);
292         vqci = kzalloc(len, GFP_KERNEL);
293         if (!vqci)
294                 return;
295
296         /* Limit maximum frame size when jumbo frames is not enabled */
297         if (!(adapter->flags & IAVF_FLAG_LEGACY_RX) &&
298             (adapter->netdev->mtu <= ETH_DATA_LEN))
299                 max_frame = IAVF_RXBUFFER_1536 - NET_IP_ALIGN;
300
301         vqci->vsi_id = adapter->vsi_res->vsi_id;
302         vqci->num_queue_pairs = pairs;
303         vqpi = vqci->qpair;
304         /* Size check is not needed here - HW max is 16 queue pairs, and we
305          * can fit info for 31 of them into the AQ buffer before it overflows.
306          */
307         for (i = 0; i < pairs; i++) {
308                 vqpi->txq.vsi_id = vqci->vsi_id;
309                 vqpi->txq.queue_id = i;
310                 vqpi->txq.ring_len = adapter->tx_rings[i].count;
311                 vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
312                 vqpi->rxq.vsi_id = vqci->vsi_id;
313                 vqpi->rxq.queue_id = i;
314                 vqpi->rxq.ring_len = adapter->rx_rings[i].count;
315                 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
316                 vqpi->rxq.max_pkt_size = max_frame;
317                 vqpi->rxq.databuffer_size =
318                         ALIGN(adapter->rx_rings[i].rx_buf_len,
319                               BIT_ULL(IAVF_RXQ_CTX_DBUFF_SHIFT));
320                 vqpi++;
321         }
322
323         adapter->aq_required &= ~IAVF_FLAG_AQ_CONFIGURE_QUEUES;
324         iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
325                          (u8 *)vqci, len);
326         kfree(vqci);
327 }
328
329 /**
330  * iavf_enable_queues
331  * @adapter: adapter structure
332  *
333  * Request that the PF enable all of our queues.
334  **/
335 void iavf_enable_queues(struct iavf_adapter *adapter)
336 {
337         struct virtchnl_queue_select vqs;
338
339         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
340                 /* bail because we already have a command pending */
341                 dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n",
342                         adapter->current_op);
343                 return;
344         }
345         adapter->current_op = VIRTCHNL_OP_ENABLE_QUEUES;
346         vqs.vsi_id = adapter->vsi_res->vsi_id;
347         vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
348         vqs.rx_queues = vqs.tx_queues;
349         adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_QUEUES;
350         iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_QUEUES,
351                          (u8 *)&vqs, sizeof(vqs));
352 }
353
354 /**
355  * iavf_disable_queues
356  * @adapter: adapter structure
357  *
358  * Request that the PF disable all of our queues.
359  **/
360 void iavf_disable_queues(struct iavf_adapter *adapter)
361 {
362         struct virtchnl_queue_select vqs;
363
364         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
365                 /* bail because we already have a command pending */
366                 dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
367                         adapter->current_op);
368                 return;
369         }
370         adapter->current_op = VIRTCHNL_OP_DISABLE_QUEUES;
371         vqs.vsi_id = adapter->vsi_res->vsi_id;
372         vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
373         vqs.rx_queues = vqs.tx_queues;
374         adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_QUEUES;
375         iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_QUEUES,
376                          (u8 *)&vqs, sizeof(vqs));
377 }
378
379 /**
380  * iavf_map_queues
381  * @adapter: adapter structure
382  *
383  * Request that the PF map queues to interrupt vectors. Misc causes, including
384  * admin queue, are always mapped to vector 0.
385  **/
386 void iavf_map_queues(struct iavf_adapter *adapter)
387 {
388         struct virtchnl_irq_map_info *vimi;
389         struct virtchnl_vector_map *vecmap;
390         struct iavf_q_vector *q_vector;
391         int v_idx, q_vectors;
392         size_t len;
393
394         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
395                 /* bail because we already have a command pending */
396                 dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
397                         adapter->current_op);
398                 return;
399         }
400         adapter->current_op = VIRTCHNL_OP_CONFIG_IRQ_MAP;
401
402         q_vectors = adapter->num_msix_vectors - NONQ_VECS;
403
404         len = struct_size(vimi, vecmap, adapter->num_msix_vectors);
405         vimi = kzalloc(len, GFP_KERNEL);
406         if (!vimi)
407                 return;
408
409         vimi->num_vectors = adapter->num_msix_vectors;
410         /* Queue vectors first */
411         for (v_idx = 0; v_idx < q_vectors; v_idx++) {
412                 q_vector = &adapter->q_vectors[v_idx];
413                 vecmap = &vimi->vecmap[v_idx];
414
415                 vecmap->vsi_id = adapter->vsi_res->vsi_id;
416                 vecmap->vector_id = v_idx + NONQ_VECS;
417                 vecmap->txq_map = q_vector->ring_mask;
418                 vecmap->rxq_map = q_vector->ring_mask;
419                 vecmap->rxitr_idx = IAVF_RX_ITR;
420                 vecmap->txitr_idx = IAVF_TX_ITR;
421         }
422         /* Misc vector last - this is only for AdminQ messages */
423         vecmap = &vimi->vecmap[v_idx];
424         vecmap->vsi_id = adapter->vsi_res->vsi_id;
425         vecmap->vector_id = 0;
426         vecmap->txq_map = 0;
427         vecmap->rxq_map = 0;
428
429         adapter->aq_required &= ~IAVF_FLAG_AQ_MAP_VECTORS;
430         iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_IRQ_MAP,
431                          (u8 *)vimi, len);
432         kfree(vimi);
433 }
434
435 /**
436  * iavf_set_mac_addr_type - Set the correct request type from the filter type
437  * @virtchnl_ether_addr: pointer to requested list element
438  * @filter: pointer to requested filter
439  **/
440 static void
441 iavf_set_mac_addr_type(struct virtchnl_ether_addr *virtchnl_ether_addr,
442                        const struct iavf_mac_filter *filter)
443 {
444         virtchnl_ether_addr->type = filter->is_primary ?
445                 VIRTCHNL_ETHER_ADDR_PRIMARY :
446                 VIRTCHNL_ETHER_ADDR_EXTRA;
447 }
448
449 /**
450  * iavf_add_ether_addrs
451  * @adapter: adapter structure
452  *
453  * Request that the PF add one or more addresses to our filters.
454  **/
455 void iavf_add_ether_addrs(struct iavf_adapter *adapter)
456 {
457         struct virtchnl_ether_addr_list *veal;
458         struct iavf_mac_filter *f;
459         int i = 0, count = 0;
460         bool more = false;
461         size_t len;
462
463         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
464                 /* bail because we already have a command pending */
465                 dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
466                         adapter->current_op);
467                 return;
468         }
469
470         spin_lock_bh(&adapter->mac_vlan_list_lock);
471
472         list_for_each_entry(f, &adapter->mac_filter_list, list) {
473                 if (f->add)
474                         count++;
475         }
476         if (!count) {
477                 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
478                 spin_unlock_bh(&adapter->mac_vlan_list_lock);
479                 return;
480         }
481         adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR;
482
483         len = struct_size(veal, list, count);
484         if (len > IAVF_MAX_AQ_BUF_SIZE) {
485                 dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
486                 count = (IAVF_MAX_AQ_BUF_SIZE -
487                          sizeof(struct virtchnl_ether_addr_list)) /
488                         sizeof(struct virtchnl_ether_addr);
489                 len = struct_size(veal, list, count);
490                 more = true;
491         }
492
493         veal = kzalloc(len, GFP_ATOMIC);
494         if (!veal) {
495                 spin_unlock_bh(&adapter->mac_vlan_list_lock);
496                 return;
497         }
498
499         veal->vsi_id = adapter->vsi_res->vsi_id;
500         veal->num_elements = count;
501         list_for_each_entry(f, &adapter->mac_filter_list, list) {
502                 if (f->add) {
503                         ether_addr_copy(veal->list[i].addr, f->macaddr);
504                         iavf_set_mac_addr_type(&veal->list[i], f);
505                         i++;
506                         f->add = false;
507                         if (i == count)
508                                 break;
509                 }
510         }
511         if (!more)
512                 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
513
514         spin_unlock_bh(&adapter->mac_vlan_list_lock);
515
516         iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR, (u8 *)veal, len);
517         kfree(veal);
518 }
519
520 /**
521  * iavf_del_ether_addrs
522  * @adapter: adapter structure
523  *
524  * Request that the PF remove one or more addresses from our filters.
525  **/
526 void iavf_del_ether_addrs(struct iavf_adapter *adapter)
527 {
528         struct virtchnl_ether_addr_list *veal;
529         struct iavf_mac_filter *f, *ftmp;
530         int i = 0, count = 0;
531         bool more = false;
532         size_t len;
533
534         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
535                 /* bail because we already have a command pending */
536                 dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
537                         adapter->current_op);
538                 return;
539         }
540
541         spin_lock_bh(&adapter->mac_vlan_list_lock);
542
543         list_for_each_entry(f, &adapter->mac_filter_list, list) {
544                 if (f->remove)
545                         count++;
546         }
547         if (!count) {
548                 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER;
549                 spin_unlock_bh(&adapter->mac_vlan_list_lock);
550                 return;
551         }
552         adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR;
553
554         len = struct_size(veal, list, count);
555         if (len > IAVF_MAX_AQ_BUF_SIZE) {
556                 dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
557                 count = (IAVF_MAX_AQ_BUF_SIZE -
558                          sizeof(struct virtchnl_ether_addr_list)) /
559                         sizeof(struct virtchnl_ether_addr);
560                 len = struct_size(veal, list, count);
561                 more = true;
562         }
563         veal = kzalloc(len, GFP_ATOMIC);
564         if (!veal) {
565                 spin_unlock_bh(&adapter->mac_vlan_list_lock);
566                 return;
567         }
568
569         veal->vsi_id = adapter->vsi_res->vsi_id;
570         veal->num_elements = count;
571         list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
572                 if (f->remove) {
573                         ether_addr_copy(veal->list[i].addr, f->macaddr);
574                         iavf_set_mac_addr_type(&veal->list[i], f);
575                         i++;
576                         list_del(&f->list);
577                         kfree(f);
578                         if (i == count)
579                                 break;
580                 }
581         }
582         if (!more)
583                 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER;
584
585         spin_unlock_bh(&adapter->mac_vlan_list_lock);
586
587         iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR, (u8 *)veal, len);
588         kfree(veal);
589 }
590
591 /**
592  * iavf_mac_add_ok
593  * @adapter: adapter structure
594  *
595  * Submit list of filters based on PF response.
596  **/
597 static void iavf_mac_add_ok(struct iavf_adapter *adapter)
598 {
599         struct iavf_mac_filter *f, *ftmp;
600
601         spin_lock_bh(&adapter->mac_vlan_list_lock);
602         list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
603                 f->is_new_mac = false;
604         }
605         spin_unlock_bh(&adapter->mac_vlan_list_lock);
606 }
607
608 /**
609  * iavf_mac_add_reject
610  * @adapter: adapter structure
611  *
612  * Remove filters from list based on PF response.
613  **/
614 static void iavf_mac_add_reject(struct iavf_adapter *adapter)
615 {
616         struct net_device *netdev = adapter->netdev;
617         struct iavf_mac_filter *f, *ftmp;
618
619         spin_lock_bh(&adapter->mac_vlan_list_lock);
620         list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
621                 if (f->remove && ether_addr_equal(f->macaddr, netdev->dev_addr))
622                         f->remove = false;
623
624                 if (f->is_new_mac) {
625                         list_del(&f->list);
626                         kfree(f);
627                 }
628         }
629         spin_unlock_bh(&adapter->mac_vlan_list_lock);
630 }
631
632 /**
633  * iavf_vlan_add_reject
634  * @adapter: adapter structure
635  *
636  * Remove VLAN filters from list based on PF response.
637  **/
638 static void iavf_vlan_add_reject(struct iavf_adapter *adapter)
639 {
640         struct iavf_vlan_filter *f, *ftmp;
641
642         spin_lock_bh(&adapter->mac_vlan_list_lock);
643         list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
644                 if (f->is_new_vlan) {
645                         if (f->vlan.tpid == ETH_P_8021Q)
646                                 clear_bit(f->vlan.vid,
647                                           adapter->vsi.active_cvlans);
648                         else
649                                 clear_bit(f->vlan.vid,
650                                           adapter->vsi.active_svlans);
651
652                         list_del(&f->list);
653                         kfree(f);
654                 }
655         }
656         spin_unlock_bh(&adapter->mac_vlan_list_lock);
657 }
658
659 /**
660  * iavf_add_vlans
661  * @adapter: adapter structure
662  *
663  * Request that the PF add one or more VLAN filters to our VSI.
664  **/
665 void iavf_add_vlans(struct iavf_adapter *adapter)
666 {
667         int len, i = 0, count = 0;
668         struct iavf_vlan_filter *f;
669         bool more = false;
670
671         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
672                 /* bail because we already have a command pending */
673                 dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
674                         adapter->current_op);
675                 return;
676         }
677
678         spin_lock_bh(&adapter->mac_vlan_list_lock);
679
680         list_for_each_entry(f, &adapter->vlan_filter_list, list) {
681                 if (f->add)
682                         count++;
683         }
684         if (!count || !VLAN_FILTERING_ALLOWED(adapter)) {
685                 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
686                 spin_unlock_bh(&adapter->mac_vlan_list_lock);
687                 return;
688         }
689
690         if (VLAN_ALLOWED(adapter)) {
691                 struct virtchnl_vlan_filter_list *vvfl;
692
693                 adapter->current_op = VIRTCHNL_OP_ADD_VLAN;
694
695                 len = sizeof(*vvfl) + (count * sizeof(u16));
696                 if (len > IAVF_MAX_AQ_BUF_SIZE) {
697                         dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
698                         count = (IAVF_MAX_AQ_BUF_SIZE - sizeof(*vvfl)) /
699                                 sizeof(u16);
700                         len = sizeof(*vvfl) + (count * sizeof(u16));
701                         more = true;
702                 }
703                 vvfl = kzalloc(len, GFP_ATOMIC);
704                 if (!vvfl) {
705                         spin_unlock_bh(&adapter->mac_vlan_list_lock);
706                         return;
707                 }
708
709                 vvfl->vsi_id = adapter->vsi_res->vsi_id;
710                 vvfl->num_elements = count;
711                 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
712                         if (f->add) {
713                                 vvfl->vlan_id[i] = f->vlan.vid;
714                                 i++;
715                                 f->add = false;
716                                 f->is_new_vlan = true;
717                                 if (i == count)
718                                         break;
719                         }
720                 }
721                 if (!more)
722                         adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
723
724                 spin_unlock_bh(&adapter->mac_vlan_list_lock);
725
726                 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
727                 kfree(vvfl);
728         } else {
729                 u16 max_vlans = adapter->vlan_v2_caps.filtering.max_filters;
730                 u16 current_vlans = iavf_get_num_vlans_added(adapter);
731                 struct virtchnl_vlan_filter_list_v2 *vvfl_v2;
732
733                 adapter->current_op = VIRTCHNL_OP_ADD_VLAN_V2;
734
735                 if ((count + current_vlans) > max_vlans &&
736                     current_vlans < max_vlans) {
737                         count = max_vlans - iavf_get_num_vlans_added(adapter);
738                         more = true;
739                 }
740
741                 len = sizeof(*vvfl_v2) + ((count - 1) *
742                                           sizeof(struct virtchnl_vlan_filter));
743                 if (len > IAVF_MAX_AQ_BUF_SIZE) {
744                         dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
745                         count = (IAVF_MAX_AQ_BUF_SIZE - sizeof(*vvfl_v2)) /
746                                 sizeof(struct virtchnl_vlan_filter);
747                         len = sizeof(*vvfl_v2) +
748                                 ((count - 1) *
749                                  sizeof(struct virtchnl_vlan_filter));
750                         more = true;
751                 }
752
753                 vvfl_v2 = kzalloc(len, GFP_ATOMIC);
754                 if (!vvfl_v2) {
755                         spin_unlock_bh(&adapter->mac_vlan_list_lock);
756                         return;
757                 }
758
759                 vvfl_v2->vport_id = adapter->vsi_res->vsi_id;
760                 vvfl_v2->num_elements = count;
761                 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
762                         if (f->add) {
763                                 struct virtchnl_vlan_supported_caps *filtering_support =
764                                         &adapter->vlan_v2_caps.filtering.filtering_support;
765                                 struct virtchnl_vlan *vlan;
766
767                                 if (i == count)
768                                         break;
769
770                                 /* give priority over outer if it's enabled */
771                                 if (filtering_support->outer)
772                                         vlan = &vvfl_v2->filters[i].outer;
773                                 else
774                                         vlan = &vvfl_v2->filters[i].inner;
775
776                                 vlan->tci = f->vlan.vid;
777                                 vlan->tpid = f->vlan.tpid;
778
779                                 i++;
780                                 f->add = false;
781                                 f->is_new_vlan = true;
782                         }
783                 }
784
785                 if (!more)
786                         adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
787
788                 spin_unlock_bh(&adapter->mac_vlan_list_lock);
789
790                 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN_V2,
791                                  (u8 *)vvfl_v2, len);
792                 kfree(vvfl_v2);
793         }
794 }
795
796 /**
797  * iavf_del_vlans
798  * @adapter: adapter structure
799  *
800  * Request that the PF remove one or more VLAN filters from our VSI.
801  **/
802 void iavf_del_vlans(struct iavf_adapter *adapter)
803 {
804         struct iavf_vlan_filter *f, *ftmp;
805         int len, i = 0, count = 0;
806         bool more = false;
807
808         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
809                 /* bail because we already have a command pending */
810                 dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
811                         adapter->current_op);
812                 return;
813         }
814
815         spin_lock_bh(&adapter->mac_vlan_list_lock);
816
817         list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
818                 /* since VLAN capabilities are not allowed, we dont want to send
819                  * a VLAN delete request because it will most likely fail and
820                  * create unnecessary errors/noise, so just free the VLAN
821                  * filters marked for removal to enable bailing out before
822                  * sending a virtchnl message
823                  */
824                 if (f->remove && !VLAN_FILTERING_ALLOWED(adapter)) {
825                         list_del(&f->list);
826                         kfree(f);
827                 } else if (f->remove) {
828                         count++;
829                 }
830         }
831         if (!count || !VLAN_FILTERING_ALLOWED(adapter)) {
832                 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
833                 spin_unlock_bh(&adapter->mac_vlan_list_lock);
834                 return;
835         }
836
837         if (VLAN_ALLOWED(adapter)) {
838                 struct virtchnl_vlan_filter_list *vvfl;
839
840                 adapter->current_op = VIRTCHNL_OP_DEL_VLAN;
841
842                 len = sizeof(*vvfl) + (count * sizeof(u16));
843                 if (len > IAVF_MAX_AQ_BUF_SIZE) {
844                         dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
845                         count = (IAVF_MAX_AQ_BUF_SIZE - sizeof(*vvfl)) /
846                                 sizeof(u16);
847                         len = sizeof(*vvfl) + (count * sizeof(u16));
848                         more = true;
849                 }
850                 vvfl = kzalloc(len, GFP_ATOMIC);
851                 if (!vvfl) {
852                         spin_unlock_bh(&adapter->mac_vlan_list_lock);
853                         return;
854                 }
855
856                 vvfl->vsi_id = adapter->vsi_res->vsi_id;
857                 vvfl->num_elements = count;
858                 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
859                         if (f->remove) {
860                                 vvfl->vlan_id[i] = f->vlan.vid;
861                                 i++;
862                                 list_del(&f->list);
863                                 kfree(f);
864                                 if (i == count)
865                                         break;
866                         }
867                 }
868
869                 if (!more)
870                         adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
871
872                 spin_unlock_bh(&adapter->mac_vlan_list_lock);
873
874                 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
875                 kfree(vvfl);
876         } else {
877                 struct virtchnl_vlan_filter_list_v2 *vvfl_v2;
878
879                 adapter->current_op = VIRTCHNL_OP_DEL_VLAN_V2;
880
881                 len = sizeof(*vvfl_v2) +
882                         ((count - 1) * sizeof(struct virtchnl_vlan_filter));
883                 if (len > IAVF_MAX_AQ_BUF_SIZE) {
884                         dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
885                         count = (IAVF_MAX_AQ_BUF_SIZE -
886                                  sizeof(*vvfl_v2)) /
887                                 sizeof(struct virtchnl_vlan_filter);
888                         len = sizeof(*vvfl_v2) +
889                                 ((count - 1) *
890                                  sizeof(struct virtchnl_vlan_filter));
891                         more = true;
892                 }
893
894                 vvfl_v2 = kzalloc(len, GFP_ATOMIC);
895                 if (!vvfl_v2) {
896                         spin_unlock_bh(&adapter->mac_vlan_list_lock);
897                         return;
898                 }
899
900                 vvfl_v2->vport_id = adapter->vsi_res->vsi_id;
901                 vvfl_v2->num_elements = count;
902                 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
903                         if (f->remove) {
904                                 struct virtchnl_vlan_supported_caps *filtering_support =
905                                         &adapter->vlan_v2_caps.filtering.filtering_support;
906                                 struct virtchnl_vlan *vlan;
907
908                                 /* give priority over outer if it's enabled */
909                                 if (filtering_support->outer)
910                                         vlan = &vvfl_v2->filters[i].outer;
911                                 else
912                                         vlan = &vvfl_v2->filters[i].inner;
913
914                                 vlan->tci = f->vlan.vid;
915                                 vlan->tpid = f->vlan.tpid;
916
917                                 list_del(&f->list);
918                                 kfree(f);
919                                 i++;
920                                 if (i == count)
921                                         break;
922                         }
923                 }
924
925                 if (!more)
926                         adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
927
928                 spin_unlock_bh(&adapter->mac_vlan_list_lock);
929
930                 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN_V2,
931                                  (u8 *)vvfl_v2, len);
932                 kfree(vvfl_v2);
933         }
934 }
935
936 /**
937  * iavf_set_promiscuous
938  * @adapter: adapter structure
939  * @flags: bitmask to control unicast/multicast promiscuous.
940  *
941  * Request that the PF enable promiscuous mode for our VSI.
942  **/
943 void iavf_set_promiscuous(struct iavf_adapter *adapter, int flags)
944 {
945         struct virtchnl_promisc_info vpi;
946         int promisc_all;
947
948         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
949                 /* bail because we already have a command pending */
950                 dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
951                         adapter->current_op);
952                 return;
953         }
954
955         promisc_all = FLAG_VF_UNICAST_PROMISC |
956                       FLAG_VF_MULTICAST_PROMISC;
957         if ((flags & promisc_all) == promisc_all) {
958                 adapter->flags |= IAVF_FLAG_PROMISC_ON;
959                 adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_PROMISC;
960                 dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
961         }
962
963         if (flags & FLAG_VF_MULTICAST_PROMISC) {
964                 adapter->flags |= IAVF_FLAG_ALLMULTI_ON;
965                 adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_ALLMULTI;
966                 dev_info(&adapter->pdev->dev, "%s is entering multicast promiscuous mode\n",
967                          adapter->netdev->name);
968         }
969
970         if (!flags) {
971                 if (adapter->flags & IAVF_FLAG_PROMISC_ON) {
972                         adapter->flags &= ~IAVF_FLAG_PROMISC_ON;
973                         adapter->aq_required &= ~IAVF_FLAG_AQ_RELEASE_PROMISC;
974                         dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
975                 }
976
977                 if (adapter->flags & IAVF_FLAG_ALLMULTI_ON) {
978                         adapter->flags &= ~IAVF_FLAG_ALLMULTI_ON;
979                         adapter->aq_required &= ~IAVF_FLAG_AQ_RELEASE_ALLMULTI;
980                         dev_info(&adapter->pdev->dev, "%s is leaving multicast promiscuous mode\n",
981                                  adapter->netdev->name);
982                 }
983         }
984
985         adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
986         vpi.vsi_id = adapter->vsi_res->vsi_id;
987         vpi.flags = flags;
988         iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
989                          (u8 *)&vpi, sizeof(vpi));
990 }
991
992 /**
993  * iavf_request_stats
994  * @adapter: adapter structure
995  *
996  * Request VSI statistics from PF.
997  **/
998 void iavf_request_stats(struct iavf_adapter *adapter)
999 {
1000         struct virtchnl_queue_select vqs;
1001
1002         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1003                 /* no error message, this isn't crucial */
1004                 return;
1005         }
1006
1007         adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_STATS;
1008         adapter->current_op = VIRTCHNL_OP_GET_STATS;
1009         vqs.vsi_id = adapter->vsi_res->vsi_id;
1010         /* queue maps are ignored for this message - only the vsi is used */
1011         if (iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS, (u8 *)&vqs,
1012                              sizeof(vqs)))
1013                 /* if the request failed, don't lock out others */
1014                 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1015 }
1016
1017 /**
1018  * iavf_get_hena
1019  * @adapter: adapter structure
1020  *
1021  * Request hash enable capabilities from PF
1022  **/
1023 void iavf_get_hena(struct iavf_adapter *adapter)
1024 {
1025         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1026                 /* bail because we already have a command pending */
1027                 dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
1028                         adapter->current_op);
1029                 return;
1030         }
1031         adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
1032         adapter->aq_required &= ~IAVF_FLAG_AQ_GET_HENA;
1033         iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS, NULL, 0);
1034 }
1035
1036 /**
1037  * iavf_set_hena
1038  * @adapter: adapter structure
1039  *
1040  * Request the PF to set our RSS hash capabilities
1041  **/
1042 void iavf_set_hena(struct iavf_adapter *adapter)
1043 {
1044         struct virtchnl_rss_hena vrh;
1045
1046         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1047                 /* bail because we already have a command pending */
1048                 dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
1049                         adapter->current_op);
1050                 return;
1051         }
1052         vrh.hena = adapter->hena;
1053         adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA;
1054         adapter->aq_required &= ~IAVF_FLAG_AQ_SET_HENA;
1055         iavf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA, (u8 *)&vrh,
1056                          sizeof(vrh));
1057 }
1058
1059 /**
1060  * iavf_set_rss_key
1061  * @adapter: adapter structure
1062  *
1063  * Request the PF to set our RSS hash key
1064  **/
1065 void iavf_set_rss_key(struct iavf_adapter *adapter)
1066 {
1067         struct virtchnl_rss_key *vrk;
1068         int len;
1069
1070         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1071                 /* bail because we already have a command pending */
1072                 dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
1073                         adapter->current_op);
1074                 return;
1075         }
1076         len = sizeof(struct virtchnl_rss_key) +
1077               (adapter->rss_key_size * sizeof(u8)) - 1;
1078         vrk = kzalloc(len, GFP_KERNEL);
1079         if (!vrk)
1080                 return;
1081         vrk->vsi_id = adapter->vsi.id;
1082         vrk->key_len = adapter->rss_key_size;
1083         memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
1084
1085         adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY;
1086         adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_KEY;
1087         iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY, (u8 *)vrk, len);
1088         kfree(vrk);
1089 }
1090
1091 /**
1092  * iavf_set_rss_lut
1093  * @adapter: adapter structure
1094  *
1095  * Request the PF to set our RSS lookup table
1096  **/
1097 void iavf_set_rss_lut(struct iavf_adapter *adapter)
1098 {
1099         struct virtchnl_rss_lut *vrl;
1100         int len;
1101
1102         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1103                 /* bail because we already have a command pending */
1104                 dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
1105                         adapter->current_op);
1106                 return;
1107         }
1108         len = sizeof(struct virtchnl_rss_lut) +
1109               (adapter->rss_lut_size * sizeof(u8)) - 1;
1110         vrl = kzalloc(len, GFP_KERNEL);
1111         if (!vrl)
1112                 return;
1113         vrl->vsi_id = adapter->vsi.id;
1114         vrl->lut_entries = adapter->rss_lut_size;
1115         memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
1116         adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT;
1117         adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_LUT;
1118         iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT, (u8 *)vrl, len);
1119         kfree(vrl);
1120 }
1121
1122 /**
1123  * iavf_enable_vlan_stripping
1124  * @adapter: adapter structure
1125  *
1126  * Request VLAN header stripping to be enabled
1127  **/
1128 void iavf_enable_vlan_stripping(struct iavf_adapter *adapter)
1129 {
1130         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1131                 /* bail because we already have a command pending */
1132                 dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n",
1133                         adapter->current_op);
1134                 return;
1135         }
1136         adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
1137         adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING;
1138         iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING, NULL, 0);
1139 }
1140
1141 /**
1142  * iavf_disable_vlan_stripping
1143  * @adapter: adapter structure
1144  *
1145  * Request VLAN header stripping to be disabled
1146  **/
1147 void iavf_disable_vlan_stripping(struct iavf_adapter *adapter)
1148 {
1149         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1150                 /* bail because we already have a command pending */
1151                 dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n",
1152                         adapter->current_op);
1153                 return;
1154         }
1155         adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
1156         adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING;
1157         iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING, NULL, 0);
1158 }
1159
1160 /**
1161  * iavf_tpid_to_vc_ethertype - transform from VLAN TPID to virtchnl ethertype
1162  * @tpid: VLAN TPID (i.e. 0x8100, 0x88a8, etc.)
1163  */
1164 static u32 iavf_tpid_to_vc_ethertype(u16 tpid)
1165 {
1166         switch (tpid) {
1167         case ETH_P_8021Q:
1168                 return VIRTCHNL_VLAN_ETHERTYPE_8100;
1169         case ETH_P_8021AD:
1170                 return VIRTCHNL_VLAN_ETHERTYPE_88A8;
1171         }
1172
1173         return 0;
1174 }
1175
1176 /**
1177  * iavf_set_vc_offload_ethertype - set virtchnl ethertype for offload message
1178  * @adapter: adapter structure
1179  * @msg: message structure used for updating offloads over virtchnl to update
1180  * @tpid: VLAN TPID (i.e. 0x8100, 0x88a8, etc.)
1181  * @offload_op: opcode used to determine which support structure to check
1182  */
1183 static int
1184 iavf_set_vc_offload_ethertype(struct iavf_adapter *adapter,
1185                               struct virtchnl_vlan_setting *msg, u16 tpid,
1186                               enum virtchnl_ops offload_op)
1187 {
1188         struct virtchnl_vlan_supported_caps *offload_support;
1189         u16 vc_ethertype = iavf_tpid_to_vc_ethertype(tpid);
1190
1191         /* reference the correct offload support structure */
1192         switch (offload_op) {
1193         case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1194         case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1195                 offload_support =
1196                         &adapter->vlan_v2_caps.offloads.stripping_support;
1197                 break;
1198         case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1199         case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1200                 offload_support =
1201                         &adapter->vlan_v2_caps.offloads.insertion_support;
1202                 break;
1203         default:
1204                 dev_err(&adapter->pdev->dev, "Invalid opcode %d for setting virtchnl ethertype to enable/disable VLAN offloads\n",
1205                         offload_op);
1206                 return -EINVAL;
1207         }
1208
1209         /* make sure ethertype is supported */
1210         if (offload_support->outer & vc_ethertype &&
1211             offload_support->outer & VIRTCHNL_VLAN_TOGGLE) {
1212                 msg->outer_ethertype_setting = vc_ethertype;
1213         } else if (offload_support->inner & vc_ethertype &&
1214                    offload_support->inner & VIRTCHNL_VLAN_TOGGLE) {
1215                 msg->inner_ethertype_setting = vc_ethertype;
1216         } else {
1217                 dev_dbg(&adapter->pdev->dev, "opcode %d unsupported for VLAN TPID 0x%04x\n",
1218                         offload_op, tpid);
1219                 return -EINVAL;
1220         }
1221
1222         return 0;
1223 }
1224
1225 /**
1226  * iavf_clear_offload_v2_aq_required - clear AQ required bit for offload request
1227  * @adapter: adapter structure
1228  * @tpid: VLAN TPID
1229  * @offload_op: opcode used to determine which AQ required bit to clear
1230  */
1231 static void
1232 iavf_clear_offload_v2_aq_required(struct iavf_adapter *adapter, u16 tpid,
1233                                   enum virtchnl_ops offload_op)
1234 {
1235         switch (offload_op) {
1236         case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2:
1237                 if (tpid == ETH_P_8021Q)
1238                         adapter->aq_required &=
1239                                 ~IAVF_FLAG_AQ_ENABLE_CTAG_VLAN_STRIPPING;
1240                 else if (tpid == ETH_P_8021AD)
1241                         adapter->aq_required &=
1242                                 ~IAVF_FLAG_AQ_ENABLE_STAG_VLAN_STRIPPING;
1243                 break;
1244         case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2:
1245                 if (tpid == ETH_P_8021Q)
1246                         adapter->aq_required &=
1247                                 ~IAVF_FLAG_AQ_DISABLE_CTAG_VLAN_STRIPPING;
1248                 else if (tpid == ETH_P_8021AD)
1249                         adapter->aq_required &=
1250                                 ~IAVF_FLAG_AQ_DISABLE_STAG_VLAN_STRIPPING;
1251                 break;
1252         case VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2:
1253                 if (tpid == ETH_P_8021Q)
1254                         adapter->aq_required &=
1255                                 ~IAVF_FLAG_AQ_ENABLE_CTAG_VLAN_INSERTION;
1256                 else if (tpid == ETH_P_8021AD)
1257                         adapter->aq_required &=
1258                                 ~IAVF_FLAG_AQ_ENABLE_STAG_VLAN_INSERTION;
1259                 break;
1260         case VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2:
1261                 if (tpid == ETH_P_8021Q)
1262                         adapter->aq_required &=
1263                                 ~IAVF_FLAG_AQ_DISABLE_CTAG_VLAN_INSERTION;
1264                 else if (tpid == ETH_P_8021AD)
1265                         adapter->aq_required &=
1266                                 ~IAVF_FLAG_AQ_DISABLE_STAG_VLAN_INSERTION;
1267                 break;
1268         default:
1269                 dev_err(&adapter->pdev->dev, "Unsupported opcode %d specified for clearing aq_required bits for VIRTCHNL_VF_OFFLOAD_VLAN_V2 offload request\n",
1270                         offload_op);
1271         }
1272 }
1273
1274 /**
1275  * iavf_send_vlan_offload_v2 - send offload enable/disable over virtchnl
1276  * @adapter: adapter structure
1277  * @tpid: VLAN TPID used for the command (i.e. 0x8100 or 0x88a8)
1278  * @offload_op: offload_op used to make the request over virtchnl
1279  */
1280 static void
1281 iavf_send_vlan_offload_v2(struct iavf_adapter *adapter, u16 tpid,
1282                           enum virtchnl_ops offload_op)
1283 {
1284         struct virtchnl_vlan_setting *msg;
1285         int len = sizeof(*msg);
1286
1287         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1288                 /* bail because we already have a command pending */
1289                 dev_err(&adapter->pdev->dev, "Cannot send %d, command %d pending\n",
1290                         offload_op, adapter->current_op);
1291                 return;
1292         }
1293
1294         adapter->current_op = offload_op;
1295
1296         msg = kzalloc(len, GFP_KERNEL);
1297         if (!msg)
1298                 return;
1299
1300         msg->vport_id = adapter->vsi_res->vsi_id;
1301
1302         /* always clear to prevent unsupported and endless requests */
1303         iavf_clear_offload_v2_aq_required(adapter, tpid, offload_op);
1304
1305         /* only send valid offload requests */
1306         if (!iavf_set_vc_offload_ethertype(adapter, msg, tpid, offload_op))
1307                 iavf_send_pf_msg(adapter, offload_op, (u8 *)msg, len);
1308         else
1309                 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1310
1311         kfree(msg);
1312 }
1313
1314 /**
1315  * iavf_enable_vlan_stripping_v2 - enable VLAN stripping
1316  * @adapter: adapter structure
1317  * @tpid: VLAN TPID used to enable VLAN stripping
1318  */
1319 void iavf_enable_vlan_stripping_v2(struct iavf_adapter *adapter, u16 tpid)
1320 {
1321         iavf_send_vlan_offload_v2(adapter, tpid,
1322                                   VIRTCHNL_OP_ENABLE_VLAN_STRIPPING_V2);
1323 }
1324
1325 /**
1326  * iavf_disable_vlan_stripping_v2 - disable VLAN stripping
1327  * @adapter: adapter structure
1328  * @tpid: VLAN TPID used to disable VLAN stripping
1329  */
1330 void iavf_disable_vlan_stripping_v2(struct iavf_adapter *adapter, u16 tpid)
1331 {
1332         iavf_send_vlan_offload_v2(adapter, tpid,
1333                                   VIRTCHNL_OP_DISABLE_VLAN_STRIPPING_V2);
1334 }
1335
1336 /**
1337  * iavf_enable_vlan_insertion_v2 - enable VLAN insertion
1338  * @adapter: adapter structure
1339  * @tpid: VLAN TPID used to enable VLAN insertion
1340  */
1341 void iavf_enable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid)
1342 {
1343         iavf_send_vlan_offload_v2(adapter, tpid,
1344                                   VIRTCHNL_OP_ENABLE_VLAN_INSERTION_V2);
1345 }
1346
1347 /**
1348  * iavf_disable_vlan_insertion_v2 - disable VLAN insertion
1349  * @adapter: adapter structure
1350  * @tpid: VLAN TPID used to disable VLAN insertion
1351  */
1352 void iavf_disable_vlan_insertion_v2(struct iavf_adapter *adapter, u16 tpid)
1353 {
1354         iavf_send_vlan_offload_v2(adapter, tpid,
1355                                   VIRTCHNL_OP_DISABLE_VLAN_INSERTION_V2);
1356 }
1357
1358 #define IAVF_MAX_SPEED_STRLEN   13
1359
1360 /**
1361  * iavf_print_link_message - print link up or down
1362  * @adapter: adapter structure
1363  *
1364  * Log a message telling the world of our wonderous link status
1365  */
1366 static void iavf_print_link_message(struct iavf_adapter *adapter)
1367 {
1368         struct net_device *netdev = adapter->netdev;
1369         int link_speed_mbps;
1370         char *speed;
1371
1372         if (!adapter->link_up) {
1373                 netdev_info(netdev, "NIC Link is Down\n");
1374                 return;
1375         }
1376
1377         speed = kzalloc(IAVF_MAX_SPEED_STRLEN, GFP_KERNEL);
1378         if (!speed)
1379                 return;
1380
1381         if (ADV_LINK_SUPPORT(adapter)) {
1382                 link_speed_mbps = adapter->link_speed_mbps;
1383                 goto print_link_msg;
1384         }
1385
1386         switch (adapter->link_speed) {
1387         case VIRTCHNL_LINK_SPEED_40GB:
1388                 link_speed_mbps = SPEED_40000;
1389                 break;
1390         case VIRTCHNL_LINK_SPEED_25GB:
1391                 link_speed_mbps = SPEED_25000;
1392                 break;
1393         case VIRTCHNL_LINK_SPEED_20GB:
1394                 link_speed_mbps = SPEED_20000;
1395                 break;
1396         case VIRTCHNL_LINK_SPEED_10GB:
1397                 link_speed_mbps = SPEED_10000;
1398                 break;
1399         case VIRTCHNL_LINK_SPEED_5GB:
1400                 link_speed_mbps = SPEED_5000;
1401                 break;
1402         case VIRTCHNL_LINK_SPEED_2_5GB:
1403                 link_speed_mbps = SPEED_2500;
1404                 break;
1405         case VIRTCHNL_LINK_SPEED_1GB:
1406                 link_speed_mbps = SPEED_1000;
1407                 break;
1408         case VIRTCHNL_LINK_SPEED_100MB:
1409                 link_speed_mbps = SPEED_100;
1410                 break;
1411         default:
1412                 link_speed_mbps = SPEED_UNKNOWN;
1413                 break;
1414         }
1415
1416 print_link_msg:
1417         if (link_speed_mbps > SPEED_1000) {
1418                 if (link_speed_mbps == SPEED_2500)
1419                         snprintf(speed, IAVF_MAX_SPEED_STRLEN, "2.5 Gbps");
1420                 else
1421                         /* convert to Gbps inline */
1422                         snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%d %s",
1423                                  link_speed_mbps / 1000, "Gbps");
1424         } else if (link_speed_mbps == SPEED_UNKNOWN) {
1425                 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%s", "Unknown Mbps");
1426         } else {
1427                 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%d %s",
1428                          link_speed_mbps, "Mbps");
1429         }
1430
1431         netdev_info(netdev, "NIC Link is Up Speed is %s Full Duplex\n", speed);
1432         kfree(speed);
1433 }
1434
1435 /**
1436  * iavf_get_vpe_link_status
1437  * @adapter: adapter structure
1438  * @vpe: virtchnl_pf_event structure
1439  *
1440  * Helper function for determining the link status
1441  **/
1442 static bool
1443 iavf_get_vpe_link_status(struct iavf_adapter *adapter,
1444                          struct virtchnl_pf_event *vpe)
1445 {
1446         if (ADV_LINK_SUPPORT(adapter))
1447                 return vpe->event_data.link_event_adv.link_status;
1448         else
1449                 return vpe->event_data.link_event.link_status;
1450 }
1451
1452 /**
1453  * iavf_set_adapter_link_speed_from_vpe
1454  * @adapter: adapter structure for which we are setting the link speed
1455  * @vpe: virtchnl_pf_event structure that contains the link speed we are setting
1456  *
1457  * Helper function for setting iavf_adapter link speed
1458  **/
1459 static void
1460 iavf_set_adapter_link_speed_from_vpe(struct iavf_adapter *adapter,
1461                                      struct virtchnl_pf_event *vpe)
1462 {
1463         if (ADV_LINK_SUPPORT(adapter))
1464                 adapter->link_speed_mbps =
1465                         vpe->event_data.link_event_adv.link_speed;
1466         else
1467                 adapter->link_speed = vpe->event_data.link_event.link_speed;
1468 }
1469
1470 /**
1471  * iavf_enable_channels
1472  * @adapter: adapter structure
1473  *
1474  * Request that the PF enable channels as specified by
1475  * the user via tc tool.
1476  **/
1477 void iavf_enable_channels(struct iavf_adapter *adapter)
1478 {
1479         struct virtchnl_tc_info *vti = NULL;
1480         size_t len;
1481         int i;
1482
1483         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1484                 /* bail because we already have a command pending */
1485                 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1486                         adapter->current_op);
1487                 return;
1488         }
1489
1490         len = struct_size(vti, list, adapter->num_tc - 1);
1491         vti = kzalloc(len, GFP_KERNEL);
1492         if (!vti)
1493                 return;
1494         vti->num_tc = adapter->num_tc;
1495         for (i = 0; i < vti->num_tc; i++) {
1496                 vti->list[i].count = adapter->ch_config.ch_info[i].count;
1497                 vti->list[i].offset = adapter->ch_config.ch_info[i].offset;
1498                 vti->list[i].pad = 0;
1499                 vti->list[i].max_tx_rate =
1500                                 adapter->ch_config.ch_info[i].max_tx_rate;
1501         }
1502
1503         adapter->ch_config.state = __IAVF_TC_RUNNING;
1504         adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1505         adapter->current_op = VIRTCHNL_OP_ENABLE_CHANNELS;
1506         adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_CHANNELS;
1507         iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_CHANNELS, (u8 *)vti, len);
1508         kfree(vti);
1509 }
1510
1511 /**
1512  * iavf_disable_channels
1513  * @adapter: adapter structure
1514  *
1515  * Request that the PF disable channels that are configured
1516  **/
1517 void iavf_disable_channels(struct iavf_adapter *adapter)
1518 {
1519         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1520                 /* bail because we already have a command pending */
1521                 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1522                         adapter->current_op);
1523                 return;
1524         }
1525
1526         adapter->ch_config.state = __IAVF_TC_INVALID;
1527         adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1528         adapter->current_op = VIRTCHNL_OP_DISABLE_CHANNELS;
1529         adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_CHANNELS;
1530         iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_CHANNELS, NULL, 0);
1531 }
1532
1533 /**
1534  * iavf_print_cloud_filter
1535  * @adapter: adapter structure
1536  * @f: cloud filter to print
1537  *
1538  * Print the cloud filter
1539  **/
1540 static void iavf_print_cloud_filter(struct iavf_adapter *adapter,
1541                                     struct virtchnl_filter *f)
1542 {
1543         switch (f->flow_type) {
1544         case VIRTCHNL_TCP_V4_FLOW:
1545                 dev_info(&adapter->pdev->dev, "dst_mac: %pM src_mac: %pM vlan_id: %hu dst_ip: %pI4 src_ip %pI4 dst_port %hu src_port %hu\n",
1546                          &f->data.tcp_spec.dst_mac,
1547                          &f->data.tcp_spec.src_mac,
1548                          ntohs(f->data.tcp_spec.vlan_id),
1549                          &f->data.tcp_spec.dst_ip[0],
1550                          &f->data.tcp_spec.src_ip[0],
1551                          ntohs(f->data.tcp_spec.dst_port),
1552                          ntohs(f->data.tcp_spec.src_port));
1553                 break;
1554         case VIRTCHNL_TCP_V6_FLOW:
1555                 dev_info(&adapter->pdev->dev, "dst_mac: %pM src_mac: %pM vlan_id: %hu dst_ip: %pI6 src_ip %pI6 dst_port %hu src_port %hu\n",
1556                          &f->data.tcp_spec.dst_mac,
1557                          &f->data.tcp_spec.src_mac,
1558                          ntohs(f->data.tcp_spec.vlan_id),
1559                          &f->data.tcp_spec.dst_ip,
1560                          &f->data.tcp_spec.src_ip,
1561                          ntohs(f->data.tcp_spec.dst_port),
1562                          ntohs(f->data.tcp_spec.src_port));
1563                 break;
1564         }
1565 }
1566
1567 /**
1568  * iavf_add_cloud_filter
1569  * @adapter: adapter structure
1570  *
1571  * Request that the PF add cloud filters as specified
1572  * by the user via tc tool.
1573  **/
1574 void iavf_add_cloud_filter(struct iavf_adapter *adapter)
1575 {
1576         struct iavf_cloud_filter *cf;
1577         struct virtchnl_filter *f;
1578         int len = 0, count = 0;
1579
1580         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1581                 /* bail because we already have a command pending */
1582                 dev_err(&adapter->pdev->dev, "Cannot add cloud filter, command %d pending\n",
1583                         adapter->current_op);
1584                 return;
1585         }
1586         list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1587                 if (cf->add) {
1588                         count++;
1589                         break;
1590                 }
1591         }
1592         if (!count) {
1593                 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_CLOUD_FILTER;
1594                 return;
1595         }
1596         adapter->current_op = VIRTCHNL_OP_ADD_CLOUD_FILTER;
1597
1598         len = sizeof(struct virtchnl_filter);
1599         f = kzalloc(len, GFP_KERNEL);
1600         if (!f)
1601                 return;
1602
1603         list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1604                 if (cf->add) {
1605                         memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1606                         cf->add = false;
1607                         cf->state = __IAVF_CF_ADD_PENDING;
1608                         iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_CLOUD_FILTER,
1609                                          (u8 *)f, len);
1610                 }
1611         }
1612         kfree(f);
1613 }
1614
1615 /**
1616  * iavf_del_cloud_filter
1617  * @adapter: adapter structure
1618  *
1619  * Request that the PF delete cloud filters as specified
1620  * by the user via tc tool.
1621  **/
1622 void iavf_del_cloud_filter(struct iavf_adapter *adapter)
1623 {
1624         struct iavf_cloud_filter *cf, *cftmp;
1625         struct virtchnl_filter *f;
1626         int len = 0, count = 0;
1627
1628         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1629                 /* bail because we already have a command pending */
1630                 dev_err(&adapter->pdev->dev, "Cannot remove cloud filter, command %d pending\n",
1631                         adapter->current_op);
1632                 return;
1633         }
1634         list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1635                 if (cf->del) {
1636                         count++;
1637                         break;
1638                 }
1639         }
1640         if (!count) {
1641                 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_CLOUD_FILTER;
1642                 return;
1643         }
1644         adapter->current_op = VIRTCHNL_OP_DEL_CLOUD_FILTER;
1645
1646         len = sizeof(struct virtchnl_filter);
1647         f = kzalloc(len, GFP_KERNEL);
1648         if (!f)
1649                 return;
1650
1651         list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, list) {
1652                 if (cf->del) {
1653                         memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1654                         cf->del = false;
1655                         cf->state = __IAVF_CF_DEL_PENDING;
1656                         iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_CLOUD_FILTER,
1657                                          (u8 *)f, len);
1658                 }
1659         }
1660         kfree(f);
1661 }
1662
1663 /**
1664  * iavf_add_fdir_filter
1665  * @adapter: the VF adapter structure
1666  *
1667  * Request that the PF add Flow Director filters as specified
1668  * by the user via ethtool.
1669  **/
1670 void iavf_add_fdir_filter(struct iavf_adapter *adapter)
1671 {
1672         struct iavf_fdir_fltr *fdir;
1673         struct virtchnl_fdir_add *f;
1674         bool process_fltr = false;
1675         int len;
1676
1677         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1678                 /* bail because we already have a command pending */
1679                 dev_err(&adapter->pdev->dev, "Cannot add Flow Director filter, command %d pending\n",
1680                         adapter->current_op);
1681                 return;
1682         }
1683
1684         len = sizeof(struct virtchnl_fdir_add);
1685         f = kzalloc(len, GFP_KERNEL);
1686         if (!f)
1687                 return;
1688
1689         spin_lock_bh(&adapter->fdir_fltr_lock);
1690         list_for_each_entry(fdir, &adapter->fdir_list_head, list) {
1691                 if (fdir->state == IAVF_FDIR_FLTR_ADD_REQUEST) {
1692                         process_fltr = true;
1693                         fdir->state = IAVF_FDIR_FLTR_ADD_PENDING;
1694                         memcpy(f, &fdir->vc_add_msg, len);
1695                         break;
1696                 }
1697         }
1698         spin_unlock_bh(&adapter->fdir_fltr_lock);
1699
1700         if (!process_fltr) {
1701                 /* prevent iavf_add_fdir_filter() from being called when there
1702                  * are no filters to add
1703                  */
1704                 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_FDIR_FILTER;
1705                 kfree(f);
1706                 return;
1707         }
1708         adapter->current_op = VIRTCHNL_OP_ADD_FDIR_FILTER;
1709         iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_FDIR_FILTER, (u8 *)f, len);
1710         kfree(f);
1711 }
1712
1713 /**
1714  * iavf_del_fdir_filter
1715  * @adapter: the VF adapter structure
1716  *
1717  * Request that the PF delete Flow Director filters as specified
1718  * by the user via ethtool.
1719  **/
1720 void iavf_del_fdir_filter(struct iavf_adapter *adapter)
1721 {
1722         struct iavf_fdir_fltr *fdir;
1723         struct virtchnl_fdir_del f;
1724         bool process_fltr = false;
1725         int len;
1726
1727         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1728                 /* bail because we already have a command pending */
1729                 dev_err(&adapter->pdev->dev, "Cannot remove Flow Director filter, command %d pending\n",
1730                         adapter->current_op);
1731                 return;
1732         }
1733
1734         len = sizeof(struct virtchnl_fdir_del);
1735
1736         spin_lock_bh(&adapter->fdir_fltr_lock);
1737         list_for_each_entry(fdir, &adapter->fdir_list_head, list) {
1738                 if (fdir->state == IAVF_FDIR_FLTR_DEL_REQUEST) {
1739                         process_fltr = true;
1740                         memset(&f, 0, len);
1741                         f.vsi_id = fdir->vc_add_msg.vsi_id;
1742                         f.flow_id = fdir->flow_id;
1743                         fdir->state = IAVF_FDIR_FLTR_DEL_PENDING;
1744                         break;
1745                 }
1746         }
1747         spin_unlock_bh(&adapter->fdir_fltr_lock);
1748
1749         if (!process_fltr) {
1750                 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_FDIR_FILTER;
1751                 return;
1752         }
1753
1754         adapter->current_op = VIRTCHNL_OP_DEL_FDIR_FILTER;
1755         iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_FDIR_FILTER, (u8 *)&f, len);
1756 }
1757
1758 /**
1759  * iavf_add_adv_rss_cfg
1760  * @adapter: the VF adapter structure
1761  *
1762  * Request that the PF add RSS configuration as specified
1763  * by the user via ethtool.
1764  **/
1765 void iavf_add_adv_rss_cfg(struct iavf_adapter *adapter)
1766 {
1767         struct virtchnl_rss_cfg *rss_cfg;
1768         struct iavf_adv_rss *rss;
1769         bool process_rss = false;
1770         int len;
1771
1772         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1773                 /* bail because we already have a command pending */
1774                 dev_err(&adapter->pdev->dev, "Cannot add RSS configuration, command %d pending\n",
1775                         adapter->current_op);
1776                 return;
1777         }
1778
1779         len = sizeof(struct virtchnl_rss_cfg);
1780         rss_cfg = kzalloc(len, GFP_KERNEL);
1781         if (!rss_cfg)
1782                 return;
1783
1784         spin_lock_bh(&adapter->adv_rss_lock);
1785         list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
1786                 if (rss->state == IAVF_ADV_RSS_ADD_REQUEST) {
1787                         process_rss = true;
1788                         rss->state = IAVF_ADV_RSS_ADD_PENDING;
1789                         memcpy(rss_cfg, &rss->cfg_msg, len);
1790                         iavf_print_adv_rss_cfg(adapter, rss,
1791                                                "Input set change for",
1792                                                "is pending");
1793                         break;
1794                 }
1795         }
1796         spin_unlock_bh(&adapter->adv_rss_lock);
1797
1798         if (process_rss) {
1799                 adapter->current_op = VIRTCHNL_OP_ADD_RSS_CFG;
1800                 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_RSS_CFG,
1801                                  (u8 *)rss_cfg, len);
1802         } else {
1803                 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_ADV_RSS_CFG;
1804         }
1805
1806         kfree(rss_cfg);
1807 }
1808
1809 /**
1810  * iavf_del_adv_rss_cfg
1811  * @adapter: the VF adapter structure
1812  *
1813  * Request that the PF delete RSS configuration as specified
1814  * by the user via ethtool.
1815  **/
1816 void iavf_del_adv_rss_cfg(struct iavf_adapter *adapter)
1817 {
1818         struct virtchnl_rss_cfg *rss_cfg;
1819         struct iavf_adv_rss *rss;
1820         bool process_rss = false;
1821         int len;
1822
1823         if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1824                 /* bail because we already have a command pending */
1825                 dev_err(&adapter->pdev->dev, "Cannot remove RSS configuration, command %d pending\n",
1826                         adapter->current_op);
1827                 return;
1828         }
1829
1830         len = sizeof(struct virtchnl_rss_cfg);
1831         rss_cfg = kzalloc(len, GFP_KERNEL);
1832         if (!rss_cfg)
1833                 return;
1834
1835         spin_lock_bh(&adapter->adv_rss_lock);
1836         list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
1837                 if (rss->state == IAVF_ADV_RSS_DEL_REQUEST) {
1838                         process_rss = true;
1839                         rss->state = IAVF_ADV_RSS_DEL_PENDING;
1840                         memcpy(rss_cfg, &rss->cfg_msg, len);
1841                         break;
1842                 }
1843         }
1844         spin_unlock_bh(&adapter->adv_rss_lock);
1845
1846         if (process_rss) {
1847                 adapter->current_op = VIRTCHNL_OP_DEL_RSS_CFG;
1848                 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_RSS_CFG,
1849                                  (u8 *)rss_cfg, len);
1850         } else {
1851                 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_ADV_RSS_CFG;
1852         }
1853
1854         kfree(rss_cfg);
1855 }
1856
1857 /**
1858  * iavf_request_reset
1859  * @adapter: adapter structure
1860  *
1861  * Request that the PF reset this VF. No response is expected.
1862  **/
1863 int iavf_request_reset(struct iavf_adapter *adapter)
1864 {
1865         int err;
1866         /* Don't check CURRENT_OP - this is always higher priority */
1867         err = iavf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0);
1868         adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1869         return err;
1870 }
1871
1872 /**
1873  * iavf_netdev_features_vlan_strip_set - update vlan strip status
1874  * @netdev: ptr to netdev being adjusted
1875  * @enable: enable or disable vlan strip
1876  *
1877  * Helper function to change vlan strip status in netdev->features.
1878  */
1879 static void iavf_netdev_features_vlan_strip_set(struct net_device *netdev,
1880                                                 const bool enable)
1881 {
1882         if (enable)
1883                 netdev->features |= NETIF_F_HW_VLAN_CTAG_RX;
1884         else
1885                 netdev->features &= ~NETIF_F_HW_VLAN_CTAG_RX;
1886 }
1887
1888 /**
1889  * iavf_virtchnl_completion
1890  * @adapter: adapter structure
1891  * @v_opcode: opcode sent by PF
1892  * @v_retval: retval sent by PF
1893  * @msg: message sent by PF
1894  * @msglen: message length
1895  *
1896  * Asynchronous completion function for admin queue messages. Rather than busy
1897  * wait, we fire off our requests and assume that no errors will be returned.
1898  * This function handles the reply messages.
1899  **/
1900 void iavf_virtchnl_completion(struct iavf_adapter *adapter,
1901                               enum virtchnl_ops v_opcode,
1902                               enum iavf_status v_retval, u8 *msg, u16 msglen)
1903 {
1904         struct net_device *netdev = adapter->netdev;
1905
1906         if (v_opcode == VIRTCHNL_OP_EVENT) {
1907                 struct virtchnl_pf_event *vpe =
1908                         (struct virtchnl_pf_event *)msg;
1909                 bool link_up = iavf_get_vpe_link_status(adapter, vpe);
1910
1911                 switch (vpe->event) {
1912                 case VIRTCHNL_EVENT_LINK_CHANGE:
1913                         iavf_set_adapter_link_speed_from_vpe(adapter, vpe);
1914
1915                         /* we've already got the right link status, bail */
1916                         if (adapter->link_up == link_up)
1917                                 break;
1918
1919                         if (link_up) {
1920                                 /* If we get link up message and start queues
1921                                  * before our queues are configured it will
1922                                  * trigger a TX hang. In that case, just ignore
1923                                  * the link status message,we'll get another one
1924                                  * after we enable queues and actually prepared
1925                                  * to send traffic.
1926                                  */
1927                                 if (adapter->state != __IAVF_RUNNING)
1928                                         break;
1929
1930                                 /* For ADq enabled VF, we reconfigure VSIs and
1931                                  * re-allocate queues. Hence wait till all
1932                                  * queues are enabled.
1933                                  */
1934                                 if (adapter->flags &
1935                                     IAVF_FLAG_QUEUES_DISABLED)
1936                                         break;
1937                         }
1938
1939                         adapter->link_up = link_up;
1940                         if (link_up) {
1941                                 netif_tx_start_all_queues(netdev);
1942                                 netif_carrier_on(netdev);
1943                         } else {
1944                                 netif_tx_stop_all_queues(netdev);
1945                                 netif_carrier_off(netdev);
1946                         }
1947                         iavf_print_link_message(adapter);
1948                         break;
1949                 case VIRTCHNL_EVENT_RESET_IMPENDING:
1950                         dev_info(&adapter->pdev->dev, "Reset indication received from the PF\n");
1951                         if (!(adapter->flags & IAVF_FLAG_RESET_PENDING)) {
1952                                 adapter->flags |= IAVF_FLAG_RESET_PENDING;
1953                                 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
1954                                 queue_work(iavf_wq, &adapter->reset_task);
1955                         }
1956                         break;
1957                 default:
1958                         dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
1959                                 vpe->event);
1960                         break;
1961                 }
1962                 return;
1963         }
1964         if (v_retval) {
1965                 switch (v_opcode) {
1966                 case VIRTCHNL_OP_ADD_VLAN:
1967                         dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
1968                                 iavf_stat_str(&adapter->hw, v_retval));
1969                         break;
1970                 case VIRTCHNL_OP_ADD_ETH_ADDR:
1971                         dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
1972                                 iavf_stat_str(&adapter->hw, v_retval));
1973                         iavf_mac_add_reject(adapter);
1974                         /* restore administratively set MAC address */
1975                         ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
1976                         break;
1977                 case VIRTCHNL_OP_DEL_VLAN:
1978                         dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
1979                                 iavf_stat_str(&adapter->hw, v_retval));
1980                         break;
1981                 case VIRTCHNL_OP_DEL_ETH_ADDR:
1982                         dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
1983                                 iavf_stat_str(&adapter->hw, v_retval));
1984                         break;
1985                 case VIRTCHNL_OP_ENABLE_CHANNELS:
1986                         dev_err(&adapter->pdev->dev, "Failed to configure queue channels, error %s\n",
1987                                 iavf_stat_str(&adapter->hw, v_retval));
1988                         adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
1989                         adapter->ch_config.state = __IAVF_TC_INVALID;
1990                         netdev_reset_tc(netdev);
1991                         netif_tx_start_all_queues(netdev);
1992                         break;
1993                 case VIRTCHNL_OP_DISABLE_CHANNELS:
1994                         dev_err(&adapter->pdev->dev, "Failed to disable queue channels, error %s\n",
1995                                 iavf_stat_str(&adapter->hw, v_retval));
1996                         adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
1997                         adapter->ch_config.state = __IAVF_TC_RUNNING;
1998                         netif_tx_start_all_queues(netdev);
1999                         break;
2000                 case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
2001                         struct iavf_cloud_filter *cf, *cftmp;
2002
2003                         list_for_each_entry_safe(cf, cftmp,
2004                                                  &adapter->cloud_filter_list,
2005                                                  list) {
2006                                 if (cf->state == __IAVF_CF_ADD_PENDING) {
2007                                         cf->state = __IAVF_CF_INVALID;
2008                                         dev_info(&adapter->pdev->dev, "Failed to add cloud filter, error %s\n",
2009                                                  iavf_stat_str(&adapter->hw,
2010                                                                v_retval));
2011                                         iavf_print_cloud_filter(adapter,
2012                                                                 &cf->f);
2013                                         list_del(&cf->list);
2014                                         kfree(cf);
2015                                         adapter->num_cloud_filters--;
2016                                 }
2017                         }
2018                         }
2019                         break;
2020                 case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
2021                         struct iavf_cloud_filter *cf;
2022
2023                         list_for_each_entry(cf, &adapter->cloud_filter_list,
2024                                             list) {
2025                                 if (cf->state == __IAVF_CF_DEL_PENDING) {
2026                                         cf->state = __IAVF_CF_ACTIVE;
2027                                         dev_info(&adapter->pdev->dev, "Failed to del cloud filter, error %s\n",
2028                                                  iavf_stat_str(&adapter->hw,
2029                                                                v_retval));
2030                                         iavf_print_cloud_filter(adapter,
2031                                                                 &cf->f);
2032                                 }
2033                         }
2034                         }
2035                         break;
2036                 case VIRTCHNL_OP_ADD_FDIR_FILTER: {
2037                         struct iavf_fdir_fltr *fdir, *fdir_tmp;
2038
2039                         spin_lock_bh(&adapter->fdir_fltr_lock);
2040                         list_for_each_entry_safe(fdir, fdir_tmp,
2041                                                  &adapter->fdir_list_head,
2042                                                  list) {
2043                                 if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) {
2044                                         dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter, error %s\n",
2045                                                  iavf_stat_str(&adapter->hw,
2046                                                                v_retval));
2047                                         iavf_print_fdir_fltr(adapter, fdir);
2048                                         if (msglen)
2049                                                 dev_err(&adapter->pdev->dev,
2050                                                         "%s\n", msg);
2051                                         list_del(&fdir->list);
2052                                         kfree(fdir);
2053                                         adapter->fdir_active_fltr--;
2054                                 }
2055                         }
2056                         spin_unlock_bh(&adapter->fdir_fltr_lock);
2057                         }
2058                         break;
2059                 case VIRTCHNL_OP_DEL_FDIR_FILTER: {
2060                         struct iavf_fdir_fltr *fdir;
2061
2062                         spin_lock_bh(&adapter->fdir_fltr_lock);
2063                         list_for_each_entry(fdir, &adapter->fdir_list_head,
2064                                             list) {
2065                                 if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING) {
2066                                         fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2067                                         dev_info(&adapter->pdev->dev, "Failed to del Flow Director filter, error %s\n",
2068                                                  iavf_stat_str(&adapter->hw,
2069                                                                v_retval));
2070                                         iavf_print_fdir_fltr(adapter, fdir);
2071                                 }
2072                         }
2073                         spin_unlock_bh(&adapter->fdir_fltr_lock);
2074                         }
2075                         break;
2076                 case VIRTCHNL_OP_ADD_RSS_CFG: {
2077                         struct iavf_adv_rss *rss, *rss_tmp;
2078
2079                         spin_lock_bh(&adapter->adv_rss_lock);
2080                         list_for_each_entry_safe(rss, rss_tmp,
2081                                                  &adapter->adv_rss_list_head,
2082                                                  list) {
2083                                 if (rss->state == IAVF_ADV_RSS_ADD_PENDING) {
2084                                         iavf_print_adv_rss_cfg(adapter, rss,
2085                                                                "Failed to change the input set for",
2086                                                                NULL);
2087                                         list_del(&rss->list);
2088                                         kfree(rss);
2089                                 }
2090                         }
2091                         spin_unlock_bh(&adapter->adv_rss_lock);
2092                         }
2093                         break;
2094                 case VIRTCHNL_OP_DEL_RSS_CFG: {
2095                         struct iavf_adv_rss *rss;
2096
2097                         spin_lock_bh(&adapter->adv_rss_lock);
2098                         list_for_each_entry(rss, &adapter->adv_rss_list_head,
2099                                             list) {
2100                                 if (rss->state == IAVF_ADV_RSS_DEL_PENDING) {
2101                                         rss->state = IAVF_ADV_RSS_ACTIVE;
2102                                         dev_err(&adapter->pdev->dev, "Failed to delete RSS configuration, error %s\n",
2103                                                 iavf_stat_str(&adapter->hw,
2104                                                               v_retval));
2105                                 }
2106                         }
2107                         spin_unlock_bh(&adapter->adv_rss_lock);
2108                         }
2109                         break;
2110                 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
2111                         dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n");
2112                         /* Vlan stripping could not be enabled by ethtool.
2113                          * Disable it in netdev->features.
2114                          */
2115                         iavf_netdev_features_vlan_strip_set(netdev, false);
2116                         break;
2117                 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
2118                         dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n");
2119                         /* Vlan stripping could not be disabled by ethtool.
2120                          * Enable it in netdev->features.
2121                          */
2122                         iavf_netdev_features_vlan_strip_set(netdev, true);
2123                         break;
2124                 case VIRTCHNL_OP_ADD_VLAN_V2:
2125                         iavf_vlan_add_reject(adapter);
2126                         dev_warn(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
2127                                  iavf_stat_str(&adapter->hw, v_retval));
2128                         break;
2129                 default:
2130                         dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
2131                                 v_retval, iavf_stat_str(&adapter->hw, v_retval),
2132                                 v_opcode);
2133                 }
2134         }
2135         switch (v_opcode) {
2136         case VIRTCHNL_OP_ADD_ETH_ADDR:
2137                 if (!v_retval)
2138                         iavf_mac_add_ok(adapter);
2139                 if (!ether_addr_equal(netdev->dev_addr, adapter->hw.mac.addr))
2140                         eth_hw_addr_set(netdev, adapter->hw.mac.addr);
2141                 break;
2142         case VIRTCHNL_OP_GET_STATS: {
2143                 struct iavf_eth_stats *stats =
2144                         (struct iavf_eth_stats *)msg;
2145                 netdev->stats.rx_packets = stats->rx_unicast +
2146                                            stats->rx_multicast +
2147                                            stats->rx_broadcast;
2148                 netdev->stats.tx_packets = stats->tx_unicast +
2149                                            stats->tx_multicast +
2150                                            stats->tx_broadcast;
2151                 netdev->stats.rx_bytes = stats->rx_bytes;
2152                 netdev->stats.tx_bytes = stats->tx_bytes;
2153                 netdev->stats.tx_errors = stats->tx_errors;
2154                 netdev->stats.rx_dropped = stats->rx_discards;
2155                 netdev->stats.tx_dropped = stats->tx_discards;
2156                 adapter->current_stats = *stats;
2157                 }
2158                 break;
2159         case VIRTCHNL_OP_GET_VF_RESOURCES: {
2160                 u16 len = sizeof(struct virtchnl_vf_resource) +
2161                           IAVF_MAX_VF_VSI *
2162                           sizeof(struct virtchnl_vsi_resource);
2163                 memcpy(adapter->vf_res, msg, min(msglen, len));
2164                 iavf_validate_num_queues(adapter);
2165                 iavf_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
2166                 if (is_zero_ether_addr(adapter->hw.mac.addr)) {
2167                         /* restore current mac address */
2168                         ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
2169                 } else {
2170                         /* refresh current mac address if changed */
2171                         eth_hw_addr_set(netdev, adapter->hw.mac.addr);
2172                         ether_addr_copy(netdev->perm_addr,
2173                                         adapter->hw.mac.addr);
2174                 }
2175                 spin_lock_bh(&adapter->mac_vlan_list_lock);
2176                 iavf_add_filter(adapter, adapter->hw.mac.addr);
2177
2178                 if (VLAN_ALLOWED(adapter)) {
2179                         if (!list_empty(&adapter->vlan_filter_list)) {
2180                                 struct iavf_vlan_filter *vlf;
2181
2182                                 /* re-add all VLAN filters over virtchnl */
2183                                 list_for_each_entry(vlf,
2184                                                     &adapter->vlan_filter_list,
2185                                                     list)
2186                                         vlf->add = true;
2187
2188                                 adapter->aq_required |=
2189                                         IAVF_FLAG_AQ_ADD_VLAN_FILTER;
2190                         }
2191                 }
2192
2193                 spin_unlock_bh(&adapter->mac_vlan_list_lock);
2194
2195                 iavf_parse_vf_resource_msg(adapter);
2196
2197                 /* negotiated VIRTCHNL_VF_OFFLOAD_VLAN_V2, so wait for the
2198                  * response to VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS to finish
2199                  * configuration
2200                  */
2201                 if (VLAN_V2_ALLOWED(adapter))
2202                         break;
2203                 /* fallthrough and finish config if VIRTCHNL_VF_OFFLOAD_VLAN_V2
2204                  * wasn't successfully negotiated with the PF
2205                  */
2206                 }
2207                 fallthrough;
2208         case VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS: {
2209                 if (v_opcode == VIRTCHNL_OP_GET_OFFLOAD_VLAN_V2_CAPS)
2210                         memcpy(&adapter->vlan_v2_caps, msg,
2211                                min_t(u16, msglen,
2212                                      sizeof(adapter->vlan_v2_caps)));
2213
2214                 iavf_process_config(adapter);
2215                 adapter->flags |= IAVF_FLAG_SETUP_NETDEV_FEATURES;
2216                 }
2217                 break;
2218         case VIRTCHNL_OP_ENABLE_QUEUES:
2219                 /* enable transmits */
2220                 iavf_irq_enable(adapter, true);
2221                 adapter->flags &= ~IAVF_FLAG_QUEUES_DISABLED;
2222                 break;
2223         case VIRTCHNL_OP_DISABLE_QUEUES:
2224                 iavf_free_all_tx_resources(adapter);
2225                 iavf_free_all_rx_resources(adapter);
2226                 if (adapter->state == __IAVF_DOWN_PENDING) {
2227                         iavf_change_state(adapter, __IAVF_DOWN);
2228                         wake_up(&adapter->down_waitqueue);
2229                 }
2230                 break;
2231         case VIRTCHNL_OP_VERSION:
2232         case VIRTCHNL_OP_CONFIG_IRQ_MAP:
2233                 /* Don't display an error if we get these out of sequence.
2234                  * If the firmware needed to get kicked, we'll get these and
2235                  * it's no problem.
2236                  */
2237                 if (v_opcode != adapter->current_op)
2238                         return;
2239                 break;
2240         case VIRTCHNL_OP_IWARP:
2241                 /* Gobble zero-length replies from the PF. They indicate that
2242                  * a previous message was received OK, and the client doesn't
2243                  * care about that.
2244                  */
2245                 if (msglen && CLIENT_ENABLED(adapter))
2246                         iavf_notify_client_message(&adapter->vsi, msg, msglen);
2247                 break;
2248
2249         case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
2250                 adapter->client_pending &=
2251                                 ~(BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP));
2252                 break;
2253         case VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
2254                 struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
2255
2256                 if (msglen == sizeof(*vrh))
2257                         adapter->hena = vrh->hena;
2258                 else
2259                         dev_warn(&adapter->pdev->dev,
2260                                  "Invalid message %d from PF\n", v_opcode);
2261                 }
2262                 break;
2263         case VIRTCHNL_OP_REQUEST_QUEUES: {
2264                 struct virtchnl_vf_res_request *vfres =
2265                         (struct virtchnl_vf_res_request *)msg;
2266
2267                 if (vfres->num_queue_pairs != adapter->num_req_queues) {
2268                         dev_info(&adapter->pdev->dev,
2269                                  "Requested %d queues, PF can support %d\n",
2270                                  adapter->num_req_queues,
2271                                  vfres->num_queue_pairs);
2272                         adapter->num_req_queues = 0;
2273                         adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
2274                 }
2275                 }
2276                 break;
2277         case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
2278                 struct iavf_cloud_filter *cf;
2279
2280                 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
2281                         if (cf->state == __IAVF_CF_ADD_PENDING)
2282                                 cf->state = __IAVF_CF_ACTIVE;
2283                 }
2284                 }
2285                 break;
2286         case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
2287                 struct iavf_cloud_filter *cf, *cftmp;
2288
2289                 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list,
2290                                          list) {
2291                         if (cf->state == __IAVF_CF_DEL_PENDING) {
2292                                 cf->state = __IAVF_CF_INVALID;
2293                                 list_del(&cf->list);
2294                                 kfree(cf);
2295                                 adapter->num_cloud_filters--;
2296                         }
2297                 }
2298                 }
2299                 break;
2300         case VIRTCHNL_OP_ADD_FDIR_FILTER: {
2301                 struct virtchnl_fdir_add *add_fltr = (struct virtchnl_fdir_add *)msg;
2302                 struct iavf_fdir_fltr *fdir, *fdir_tmp;
2303
2304                 spin_lock_bh(&adapter->fdir_fltr_lock);
2305                 list_for_each_entry_safe(fdir, fdir_tmp,
2306                                          &adapter->fdir_list_head,
2307                                          list) {
2308                         if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) {
2309                                 if (add_fltr->status == VIRTCHNL_FDIR_SUCCESS) {
2310                                         dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is added\n",
2311                                                  fdir->loc);
2312                                         fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2313                                         fdir->flow_id = add_fltr->flow_id;
2314                                 } else {
2315                                         dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter with status: %d\n",
2316                                                  add_fltr->status);
2317                                         iavf_print_fdir_fltr(adapter, fdir);
2318                                         list_del(&fdir->list);
2319                                         kfree(fdir);
2320                                         adapter->fdir_active_fltr--;
2321                                 }
2322                         }
2323                 }
2324                 spin_unlock_bh(&adapter->fdir_fltr_lock);
2325                 }
2326                 break;
2327         case VIRTCHNL_OP_DEL_FDIR_FILTER: {
2328                 struct virtchnl_fdir_del *del_fltr = (struct virtchnl_fdir_del *)msg;
2329                 struct iavf_fdir_fltr *fdir, *fdir_tmp;
2330
2331                 spin_lock_bh(&adapter->fdir_fltr_lock);
2332                 list_for_each_entry_safe(fdir, fdir_tmp, &adapter->fdir_list_head,
2333                                          list) {
2334                         if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING) {
2335                                 if (del_fltr->status == VIRTCHNL_FDIR_SUCCESS) {
2336                                         dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is deleted\n",
2337                                                  fdir->loc);
2338                                         list_del(&fdir->list);
2339                                         kfree(fdir);
2340                                         adapter->fdir_active_fltr--;
2341                                 } else {
2342                                         fdir->state = IAVF_FDIR_FLTR_ACTIVE;
2343                                         dev_info(&adapter->pdev->dev, "Failed to delete Flow Director filter with status: %d\n",
2344                                                  del_fltr->status);
2345                                         iavf_print_fdir_fltr(adapter, fdir);
2346                                 }
2347                         }
2348                 }
2349                 spin_unlock_bh(&adapter->fdir_fltr_lock);
2350                 }
2351                 break;
2352         case VIRTCHNL_OP_ADD_RSS_CFG: {
2353                 struct iavf_adv_rss *rss;
2354
2355                 spin_lock_bh(&adapter->adv_rss_lock);
2356                 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
2357                         if (rss->state == IAVF_ADV_RSS_ADD_PENDING) {
2358                                 iavf_print_adv_rss_cfg(adapter, rss,
2359                                                        "Input set change for",
2360                                                        "successful");
2361                                 rss->state = IAVF_ADV_RSS_ACTIVE;
2362                         }
2363                 }
2364                 spin_unlock_bh(&adapter->adv_rss_lock);
2365                 }
2366                 break;
2367         case VIRTCHNL_OP_DEL_RSS_CFG: {
2368                 struct iavf_adv_rss *rss, *rss_tmp;
2369
2370                 spin_lock_bh(&adapter->adv_rss_lock);
2371                 list_for_each_entry_safe(rss, rss_tmp,
2372                                          &adapter->adv_rss_list_head, list) {
2373                         if (rss->state == IAVF_ADV_RSS_DEL_PENDING) {
2374                                 list_del(&rss->list);
2375                                 kfree(rss);
2376                         }
2377                 }
2378                 spin_unlock_bh(&adapter->adv_rss_lock);
2379                 }
2380                 break;
2381         case VIRTCHNL_OP_ADD_VLAN_V2: {
2382                 struct iavf_vlan_filter *f;
2383
2384                 spin_lock_bh(&adapter->mac_vlan_list_lock);
2385                 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
2386                         if (f->is_new_vlan) {
2387                                 f->is_new_vlan = false;
2388                                 if (f->vlan.tpid == ETH_P_8021Q)
2389                                         set_bit(f->vlan.vid,
2390                                                 adapter->vsi.active_cvlans);
2391                                 else
2392                                         set_bit(f->vlan.vid,
2393                                                 adapter->vsi.active_svlans);
2394                         }
2395                 }
2396                 spin_unlock_bh(&adapter->mac_vlan_list_lock);
2397                 }
2398                 break;
2399         case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
2400                 /* PF enabled vlan strip on this VF.
2401                  * Update netdev->features if needed to be in sync with ethtool.
2402                  */
2403                 if (!v_retval)
2404                         iavf_netdev_features_vlan_strip_set(netdev, true);
2405                 break;
2406         case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
2407                 /* PF disabled vlan strip on this VF.
2408                  * Update netdev->features if needed to be in sync with ethtool.
2409                  */
2410                 if (!v_retval)
2411                         iavf_netdev_features_vlan_strip_set(netdev, false);
2412                 break;
2413         default:
2414                 if (adapter->current_op && (v_opcode != adapter->current_op))
2415                         dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
2416                                  adapter->current_op, v_opcode);
2417                 break;
2418         } /* switch v_opcode */
2419         adapter->current_op = VIRTCHNL_OP_UNKNOWN;
2420 }