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 **/
iavf_send_pf_msg(struct iavf_adapter * adapter,enum virtchnl_ops op,u8 * msg,u16 len)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 err;
26
27 if (adapter->flags & IAVF_FLAG_PF_COMMS_FAILED)
28 return 0; /* nothing to see here, move along */
29
30 err = iavf_aq_send_msg_to_pf(hw, op, 0, msg, len, NULL);
31 if (err)
32 dev_dbg(&adapter->pdev->dev, "Unable to send opcode %d to PF, err %s, aq_err %s\n",
33 op, iavf_stat_str(hw, err),
34 iavf_aq_str(hw, hw->aq.asq_last_status));
35 return err;
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 **/
iavf_send_api_ver(struct iavf_adapter * adapter)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_verify_api_ver
59 * @adapter: adapter structure
60 *
61 * Compare API versions with the PF. Must be called after admin queue is
62 * initialized. Returns 0 if API versions match, -EIO if they do not,
63 * IAVF_ERR_ADMIN_QUEUE_NO_WORK if the admin queue is empty, and any errors
64 * from the firmware are propagated.
65 **/
iavf_verify_api_ver(struct iavf_adapter * adapter)66 int iavf_verify_api_ver(struct iavf_adapter *adapter)
67 {
68 struct virtchnl_version_info *pf_vvi;
69 struct iavf_hw *hw = &adapter->hw;
70 struct iavf_arq_event_info event;
71 enum virtchnl_ops op;
72 enum iavf_status err;
73
74 event.buf_len = IAVF_MAX_AQ_BUF_SIZE;
75 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
76 if (!event.msg_buf) {
77 err = -ENOMEM;
78 goto out;
79 }
80
81 while (1) {
82 err = iavf_clean_arq_element(hw, &event, NULL);
83 /* When the AQ is empty, iavf_clean_arq_element will return
84 * nonzero and this loop will terminate.
85 */
86 if (err)
87 goto out_alloc;
88 op =
89 (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
90 if (op == VIRTCHNL_OP_VERSION)
91 break;
92 }
93
94
95 err = (enum iavf_status)le32_to_cpu(event.desc.cookie_low);
96 if (err)
97 goto out_alloc;
98
99 if (op != VIRTCHNL_OP_VERSION) {
100 dev_info(&adapter->pdev->dev, "Invalid reply type %d from PF\n",
101 op);
102 err = -EIO;
103 goto out_alloc;
104 }
105
106 pf_vvi = (struct virtchnl_version_info *)event.msg_buf;
107 adapter->pf_version = *pf_vvi;
108
109 if ((pf_vvi->major > VIRTCHNL_VERSION_MAJOR) ||
110 ((pf_vvi->major == VIRTCHNL_VERSION_MAJOR) &&
111 (pf_vvi->minor > VIRTCHNL_VERSION_MINOR)))
112 err = -EIO;
113
114 out_alloc:
115 kfree(event.msg_buf);
116 out:
117 return err;
118 }
119
120 /**
121 * iavf_send_vf_config_msg
122 * @adapter: adapter structure
123 *
124 * Send VF configuration request admin queue message to the PF. The reply
125 * is not checked in this function. Returns 0 if the message was
126 * successfully sent, or one of the IAVF_ADMIN_QUEUE_ERROR_ statuses if not.
127 **/
iavf_send_vf_config_msg(struct iavf_adapter * adapter)128 int iavf_send_vf_config_msg(struct iavf_adapter *adapter)
129 {
130 u32 caps;
131
132 caps = VIRTCHNL_VF_OFFLOAD_L2 |
133 VIRTCHNL_VF_OFFLOAD_RSS_PF |
134 VIRTCHNL_VF_OFFLOAD_RSS_AQ |
135 VIRTCHNL_VF_OFFLOAD_RSS_REG |
136 VIRTCHNL_VF_OFFLOAD_VLAN |
137 VIRTCHNL_VF_OFFLOAD_WB_ON_ITR |
138 VIRTCHNL_VF_OFFLOAD_RSS_PCTYPE_V2 |
139 VIRTCHNL_VF_OFFLOAD_ENCAP |
140 VIRTCHNL_VF_OFFLOAD_ENCAP_CSUM |
141 VIRTCHNL_VF_OFFLOAD_REQ_QUEUES |
142 VIRTCHNL_VF_OFFLOAD_ADQ |
143 VIRTCHNL_VF_OFFLOAD_USO |
144 VIRTCHNL_VF_OFFLOAD_FDIR_PF |
145 VIRTCHNL_VF_OFFLOAD_ADV_RSS_PF |
146 VIRTCHNL_VF_CAP_ADV_LINK_SPEED;
147
148 adapter->current_op = VIRTCHNL_OP_GET_VF_RESOURCES;
149 adapter->aq_required &= ~IAVF_FLAG_AQ_GET_CONFIG;
150 if (PF_IS_V11(adapter))
151 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES,
152 (u8 *)&caps, sizeof(caps));
153 else
154 return iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_VF_RESOURCES,
155 NULL, 0);
156 }
157
158 /**
159 * iavf_validate_num_queues
160 * @adapter: adapter structure
161 *
162 * Validate that the number of queues the PF has sent in
163 * VIRTCHNL_OP_GET_VF_RESOURCES is not larger than the VF can handle.
164 **/
iavf_validate_num_queues(struct iavf_adapter * adapter)165 static void iavf_validate_num_queues(struct iavf_adapter *adapter)
166 {
167 if (adapter->vf_res->num_queue_pairs > IAVF_MAX_REQ_QUEUES) {
168 struct virtchnl_vsi_resource *vsi_res;
169 int i;
170
171 dev_info(&adapter->pdev->dev, "Received %d queues, but can only have a max of %d\n",
172 adapter->vf_res->num_queue_pairs,
173 IAVF_MAX_REQ_QUEUES);
174 dev_info(&adapter->pdev->dev, "Fixing by reducing queues to %d\n",
175 IAVF_MAX_REQ_QUEUES);
176 adapter->vf_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES;
177 for (i = 0; i < adapter->vf_res->num_vsis; i++) {
178 vsi_res = &adapter->vf_res->vsi_res[i];
179 vsi_res->num_queue_pairs = IAVF_MAX_REQ_QUEUES;
180 }
181 }
182 }
183
184 /**
185 * iavf_get_vf_config
186 * @adapter: private adapter structure
187 *
188 * Get VF configuration from PF and populate hw structure. Must be called after
189 * admin queue is initialized. Busy waits until response is received from PF,
190 * with maximum timeout. Response from PF is returned in the buffer for further
191 * processing by the caller.
192 **/
iavf_get_vf_config(struct iavf_adapter * adapter)193 int iavf_get_vf_config(struct iavf_adapter *adapter)
194 {
195 struct iavf_hw *hw = &adapter->hw;
196 struct iavf_arq_event_info event;
197 enum virtchnl_ops op;
198 enum iavf_status err;
199 u16 len;
200
201 len = sizeof(struct virtchnl_vf_resource) +
202 IAVF_MAX_VF_VSI * sizeof(struct virtchnl_vsi_resource);
203 event.buf_len = len;
204 event.msg_buf = kzalloc(event.buf_len, GFP_KERNEL);
205 if (!event.msg_buf) {
206 err = -ENOMEM;
207 goto out;
208 }
209
210 while (1) {
211 /* When the AQ is empty, iavf_clean_arq_element will return
212 * nonzero and this loop will terminate.
213 */
214 err = iavf_clean_arq_element(hw, &event, NULL);
215 if (err)
216 goto out_alloc;
217 op =
218 (enum virtchnl_ops)le32_to_cpu(event.desc.cookie_high);
219 if (op == VIRTCHNL_OP_GET_VF_RESOURCES)
220 break;
221 }
222
223 err = (enum iavf_status)le32_to_cpu(event.desc.cookie_low);
224 memcpy(adapter->vf_res, event.msg_buf, min(event.msg_len, len));
225
226 /* some PFs send more queues than we should have so validate that
227 * we aren't getting too many queues
228 */
229 if (!err)
230 iavf_validate_num_queues(adapter);
231 iavf_vf_parse_hw_config(hw, adapter->vf_res);
232 out_alloc:
233 kfree(event.msg_buf);
234 out:
235 return err;
236 }
237
238 /**
239 * iavf_configure_queues
240 * @adapter: adapter structure
241 *
242 * Request that the PF set up our (previously allocated) queues.
243 **/
iavf_configure_queues(struct iavf_adapter * adapter)244 void iavf_configure_queues(struct iavf_adapter *adapter)
245 {
246 struct virtchnl_vsi_queue_config_info *vqci;
247 struct virtchnl_queue_pair_info *vqpi;
248 int pairs = adapter->num_active_queues;
249 int i, max_frame = IAVF_MAX_RXBUFFER;
250 size_t len;
251
252 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
253 /* bail because we already have a command pending */
254 dev_err(&adapter->pdev->dev, "Cannot configure queues, command %d pending\n",
255 adapter->current_op);
256 return;
257 }
258 adapter->current_op = VIRTCHNL_OP_CONFIG_VSI_QUEUES;
259 len = struct_size(vqci, qpair, pairs);
260 vqci = kzalloc(len, GFP_KERNEL);
261 if (!vqci)
262 return;
263
264 /* Limit maximum frame size when jumbo frames is not enabled */
265 if (!(adapter->flags & IAVF_FLAG_LEGACY_RX) &&
266 (adapter->netdev->mtu <= ETH_DATA_LEN))
267 max_frame = IAVF_RXBUFFER_1536 - NET_IP_ALIGN;
268
269 vqci->vsi_id = adapter->vsi_res->vsi_id;
270 vqci->num_queue_pairs = pairs;
271 vqpi = vqci->qpair;
272 /* Size check is not needed here - HW max is 16 queue pairs, and we
273 * can fit info for 31 of them into the AQ buffer before it overflows.
274 */
275 for (i = 0; i < pairs; i++) {
276 vqpi->txq.vsi_id = vqci->vsi_id;
277 vqpi->txq.queue_id = i;
278 vqpi->txq.ring_len = adapter->tx_rings[i].count;
279 vqpi->txq.dma_ring_addr = adapter->tx_rings[i].dma;
280 vqpi->rxq.vsi_id = vqci->vsi_id;
281 vqpi->rxq.queue_id = i;
282 vqpi->rxq.ring_len = adapter->rx_rings[i].count;
283 vqpi->rxq.dma_ring_addr = adapter->rx_rings[i].dma;
284 vqpi->rxq.max_pkt_size = max_frame;
285 vqpi->rxq.databuffer_size =
286 ALIGN(adapter->rx_rings[i].rx_buf_len,
287 BIT_ULL(IAVF_RXQ_CTX_DBUFF_SHIFT));
288 vqpi++;
289 }
290
291 adapter->aq_required &= ~IAVF_FLAG_AQ_CONFIGURE_QUEUES;
292 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_VSI_QUEUES,
293 (u8 *)vqci, len);
294 kfree(vqci);
295 }
296
297 /**
298 * iavf_enable_queues
299 * @adapter: adapter structure
300 *
301 * Request that the PF enable all of our queues.
302 **/
iavf_enable_queues(struct iavf_adapter * adapter)303 void iavf_enable_queues(struct iavf_adapter *adapter)
304 {
305 struct virtchnl_queue_select vqs;
306
307 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
308 /* bail because we already have a command pending */
309 dev_err(&adapter->pdev->dev, "Cannot enable queues, command %d pending\n",
310 adapter->current_op);
311 return;
312 }
313 adapter->current_op = VIRTCHNL_OP_ENABLE_QUEUES;
314 vqs.vsi_id = adapter->vsi_res->vsi_id;
315 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
316 vqs.rx_queues = vqs.tx_queues;
317 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_QUEUES;
318 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_QUEUES,
319 (u8 *)&vqs, sizeof(vqs));
320 }
321
322 /**
323 * iavf_disable_queues
324 * @adapter: adapter structure
325 *
326 * Request that the PF disable all of our queues.
327 **/
iavf_disable_queues(struct iavf_adapter * adapter)328 void iavf_disable_queues(struct iavf_adapter *adapter)
329 {
330 struct virtchnl_queue_select vqs;
331
332 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
333 /* bail because we already have a command pending */
334 dev_err(&adapter->pdev->dev, "Cannot disable queues, command %d pending\n",
335 adapter->current_op);
336 return;
337 }
338 adapter->current_op = VIRTCHNL_OP_DISABLE_QUEUES;
339 vqs.vsi_id = adapter->vsi_res->vsi_id;
340 vqs.tx_queues = BIT(adapter->num_active_queues) - 1;
341 vqs.rx_queues = vqs.tx_queues;
342 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_QUEUES;
343 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_QUEUES,
344 (u8 *)&vqs, sizeof(vqs));
345 }
346
347 /**
348 * iavf_map_queues
349 * @adapter: adapter structure
350 *
351 * Request that the PF map queues to interrupt vectors. Misc causes, including
352 * admin queue, are always mapped to vector 0.
353 **/
iavf_map_queues(struct iavf_adapter * adapter)354 void iavf_map_queues(struct iavf_adapter *adapter)
355 {
356 struct virtchnl_irq_map_info *vimi;
357 struct virtchnl_vector_map *vecmap;
358 struct iavf_q_vector *q_vector;
359 int v_idx, q_vectors;
360 size_t len;
361
362 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
363 /* bail because we already have a command pending */
364 dev_err(&adapter->pdev->dev, "Cannot map queues to vectors, command %d pending\n",
365 adapter->current_op);
366 return;
367 }
368 adapter->current_op = VIRTCHNL_OP_CONFIG_IRQ_MAP;
369
370 q_vectors = adapter->num_msix_vectors - NONQ_VECS;
371
372 len = struct_size(vimi, vecmap, adapter->num_msix_vectors);
373 vimi = kzalloc(len, GFP_KERNEL);
374 if (!vimi)
375 return;
376
377 vimi->num_vectors = adapter->num_msix_vectors;
378 /* Queue vectors first */
379 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
380 q_vector = &adapter->q_vectors[v_idx];
381 vecmap = &vimi->vecmap[v_idx];
382
383 vecmap->vsi_id = adapter->vsi_res->vsi_id;
384 vecmap->vector_id = v_idx + NONQ_VECS;
385 vecmap->txq_map = q_vector->ring_mask;
386 vecmap->rxq_map = q_vector->ring_mask;
387 vecmap->rxitr_idx = IAVF_RX_ITR;
388 vecmap->txitr_idx = IAVF_TX_ITR;
389 }
390 /* Misc vector last - this is only for AdminQ messages */
391 vecmap = &vimi->vecmap[v_idx];
392 vecmap->vsi_id = adapter->vsi_res->vsi_id;
393 vecmap->vector_id = 0;
394 vecmap->txq_map = 0;
395 vecmap->rxq_map = 0;
396
397 adapter->aq_required &= ~IAVF_FLAG_AQ_MAP_VECTORS;
398 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_IRQ_MAP,
399 (u8 *)vimi, len);
400 kfree(vimi);
401 }
402
403 /**
404 * iavf_add_ether_addrs
405 * @adapter: adapter structure
406 *
407 * Request that the PF add one or more addresses to our filters.
408 **/
iavf_add_ether_addrs(struct iavf_adapter * adapter)409 void iavf_add_ether_addrs(struct iavf_adapter *adapter)
410 {
411 struct virtchnl_ether_addr_list *veal;
412 struct iavf_mac_filter *f;
413 int i = 0, count = 0;
414 bool more = false;
415 size_t len;
416
417 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
418 /* bail because we already have a command pending */
419 dev_err(&adapter->pdev->dev, "Cannot add filters, command %d pending\n",
420 adapter->current_op);
421 return;
422 }
423
424 spin_lock_bh(&adapter->mac_vlan_list_lock);
425
426 list_for_each_entry(f, &adapter->mac_filter_list, list) {
427 if (f->add)
428 count++;
429 }
430 if (!count) {
431 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
432 spin_unlock_bh(&adapter->mac_vlan_list_lock);
433 return;
434 }
435 adapter->current_op = VIRTCHNL_OP_ADD_ETH_ADDR;
436
437 len = struct_size(veal, list, count);
438 if (len > IAVF_MAX_AQ_BUF_SIZE) {
439 dev_warn(&adapter->pdev->dev, "Too many add MAC changes in one request\n");
440 count = (IAVF_MAX_AQ_BUF_SIZE -
441 sizeof(struct virtchnl_ether_addr_list)) /
442 sizeof(struct virtchnl_ether_addr);
443 len = struct_size(veal, list, count);
444 more = true;
445 }
446
447 veal = kzalloc(len, GFP_ATOMIC);
448 if (!veal) {
449 spin_unlock_bh(&adapter->mac_vlan_list_lock);
450 return;
451 }
452
453 veal->vsi_id = adapter->vsi_res->vsi_id;
454 veal->num_elements = count;
455 list_for_each_entry(f, &adapter->mac_filter_list, list) {
456 if (f->add) {
457 ether_addr_copy(veal->list[i].addr, f->macaddr);
458 i++;
459 f->add = false;
460 if (i == count)
461 break;
462 }
463 }
464 if (!more)
465 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_MAC_FILTER;
466
467 spin_unlock_bh(&adapter->mac_vlan_list_lock);
468
469 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_ETH_ADDR, (u8 *)veal, len);
470 kfree(veal);
471 }
472
473 /**
474 * iavf_del_ether_addrs
475 * @adapter: adapter structure
476 *
477 * Request that the PF remove one or more addresses from our filters.
478 **/
iavf_del_ether_addrs(struct iavf_adapter * adapter)479 void iavf_del_ether_addrs(struct iavf_adapter *adapter)
480 {
481 struct virtchnl_ether_addr_list *veal;
482 struct iavf_mac_filter *f, *ftmp;
483 int i = 0, count = 0;
484 bool more = false;
485 size_t len;
486
487 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
488 /* bail because we already have a command pending */
489 dev_err(&adapter->pdev->dev, "Cannot remove filters, command %d pending\n",
490 adapter->current_op);
491 return;
492 }
493
494 spin_lock_bh(&adapter->mac_vlan_list_lock);
495
496 list_for_each_entry(f, &adapter->mac_filter_list, list) {
497 if (f->remove)
498 count++;
499 }
500 if (!count) {
501 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER;
502 spin_unlock_bh(&adapter->mac_vlan_list_lock);
503 return;
504 }
505 adapter->current_op = VIRTCHNL_OP_DEL_ETH_ADDR;
506
507 len = struct_size(veal, list, count);
508 if (len > IAVF_MAX_AQ_BUF_SIZE) {
509 dev_warn(&adapter->pdev->dev, "Too many delete MAC changes in one request\n");
510 count = (IAVF_MAX_AQ_BUF_SIZE -
511 sizeof(struct virtchnl_ether_addr_list)) /
512 sizeof(struct virtchnl_ether_addr);
513 len = struct_size(veal, list, count);
514 more = true;
515 }
516 veal = kzalloc(len, GFP_ATOMIC);
517 if (!veal) {
518 spin_unlock_bh(&adapter->mac_vlan_list_lock);
519 return;
520 }
521
522 veal->vsi_id = adapter->vsi_res->vsi_id;
523 veal->num_elements = count;
524 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
525 if (f->remove) {
526 ether_addr_copy(veal->list[i].addr, f->macaddr);
527 i++;
528 list_del(&f->list);
529 kfree(f);
530 if (i == count)
531 break;
532 }
533 }
534 if (!more)
535 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_MAC_FILTER;
536
537 spin_unlock_bh(&adapter->mac_vlan_list_lock);
538
539 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_ETH_ADDR, (u8 *)veal, len);
540 kfree(veal);
541 }
542
543 /**
544 * iavf_mac_add_ok
545 * @adapter: adapter structure
546 *
547 * Submit list of filters based on PF response.
548 **/
iavf_mac_add_ok(struct iavf_adapter * adapter)549 static void iavf_mac_add_ok(struct iavf_adapter *adapter)
550 {
551 struct iavf_mac_filter *f, *ftmp;
552
553 spin_lock_bh(&adapter->mac_vlan_list_lock);
554 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
555 f->is_new_mac = false;
556 }
557 spin_unlock_bh(&adapter->mac_vlan_list_lock);
558 }
559
560 /**
561 * iavf_mac_add_reject
562 * @adapter: adapter structure
563 *
564 * Remove filters from list based on PF response.
565 **/
iavf_mac_add_reject(struct iavf_adapter * adapter)566 static void iavf_mac_add_reject(struct iavf_adapter *adapter)
567 {
568 struct net_device *netdev = adapter->netdev;
569 struct iavf_mac_filter *f, *ftmp;
570
571 spin_lock_bh(&adapter->mac_vlan_list_lock);
572 list_for_each_entry_safe(f, ftmp, &adapter->mac_filter_list, list) {
573 if (f->remove && ether_addr_equal(f->macaddr, netdev->dev_addr))
574 f->remove = false;
575
576 if (f->is_new_mac) {
577 list_del(&f->list);
578 kfree(f);
579 }
580 }
581 spin_unlock_bh(&adapter->mac_vlan_list_lock);
582 }
583
584 /**
585 * iavf_add_vlans
586 * @adapter: adapter structure
587 *
588 * Request that the PF add one or more VLAN filters to our VSI.
589 **/
iavf_add_vlans(struct iavf_adapter * adapter)590 void iavf_add_vlans(struct iavf_adapter *adapter)
591 {
592 struct virtchnl_vlan_filter_list *vvfl;
593 int len, i = 0, count = 0;
594 struct iavf_vlan_filter *f;
595 bool more = false;
596
597 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
598 /* bail because we already have a command pending */
599 dev_err(&adapter->pdev->dev, "Cannot add VLANs, command %d pending\n",
600 adapter->current_op);
601 return;
602 }
603
604 spin_lock_bh(&adapter->mac_vlan_list_lock);
605
606 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
607 if (f->add)
608 count++;
609 }
610 if (!count || !VLAN_ALLOWED(adapter)) {
611 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
612 spin_unlock_bh(&adapter->mac_vlan_list_lock);
613 return;
614 }
615 adapter->current_op = VIRTCHNL_OP_ADD_VLAN;
616
617 len = sizeof(struct virtchnl_vlan_filter_list) +
618 (count * sizeof(u16));
619 if (len > IAVF_MAX_AQ_BUF_SIZE) {
620 dev_warn(&adapter->pdev->dev, "Too many add VLAN changes in one request\n");
621 count = (IAVF_MAX_AQ_BUF_SIZE -
622 sizeof(struct virtchnl_vlan_filter_list)) /
623 sizeof(u16);
624 len = sizeof(struct virtchnl_vlan_filter_list) +
625 (count * sizeof(u16));
626 more = true;
627 }
628 vvfl = kzalloc(len, GFP_ATOMIC);
629 if (!vvfl) {
630 spin_unlock_bh(&adapter->mac_vlan_list_lock);
631 return;
632 }
633
634 vvfl->vsi_id = adapter->vsi_res->vsi_id;
635 vvfl->num_elements = count;
636 list_for_each_entry(f, &adapter->vlan_filter_list, list) {
637 if (f->add) {
638 vvfl->vlan_id[i] = f->vlan;
639 i++;
640 f->add = false;
641 if (i == count)
642 break;
643 }
644 }
645 if (!more)
646 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_VLAN_FILTER;
647
648 spin_unlock_bh(&adapter->mac_vlan_list_lock);
649
650 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_VLAN, (u8 *)vvfl, len);
651 kfree(vvfl);
652 }
653
654 /**
655 * iavf_del_vlans
656 * @adapter: adapter structure
657 *
658 * Request that the PF remove one or more VLAN filters from our VSI.
659 **/
iavf_del_vlans(struct iavf_adapter * adapter)660 void iavf_del_vlans(struct iavf_adapter *adapter)
661 {
662 struct virtchnl_vlan_filter_list *vvfl;
663 struct iavf_vlan_filter *f, *ftmp;
664 int len, i = 0, count = 0;
665 bool more = false;
666
667 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
668 /* bail because we already have a command pending */
669 dev_err(&adapter->pdev->dev, "Cannot remove VLANs, command %d pending\n",
670 adapter->current_op);
671 return;
672 }
673
674 spin_lock_bh(&adapter->mac_vlan_list_lock);
675
676 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
677 /* since VLAN capabilities are not allowed, we dont want to send
678 * a VLAN delete request because it will most likely fail and
679 * create unnecessary errors/noise, so just free the VLAN
680 * filters marked for removal to enable bailing out before
681 * sending a virtchnl message
682 */
683 if (f->remove && !VLAN_ALLOWED(adapter)) {
684 list_del(&f->list);
685 kfree(f);
686 } else if (f->remove) {
687 count++;
688 }
689 }
690 if (!count) {
691 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
692 spin_unlock_bh(&adapter->mac_vlan_list_lock);
693 return;
694 }
695 adapter->current_op = VIRTCHNL_OP_DEL_VLAN;
696
697 len = sizeof(struct virtchnl_vlan_filter_list) +
698 (count * sizeof(u16));
699 if (len > IAVF_MAX_AQ_BUF_SIZE) {
700 dev_warn(&adapter->pdev->dev, "Too many delete VLAN changes in one request\n");
701 count = (IAVF_MAX_AQ_BUF_SIZE -
702 sizeof(struct virtchnl_vlan_filter_list)) /
703 sizeof(u16);
704 len = sizeof(struct virtchnl_vlan_filter_list) +
705 (count * sizeof(u16));
706 more = true;
707 }
708 vvfl = kzalloc(len, GFP_ATOMIC);
709 if (!vvfl) {
710 spin_unlock_bh(&adapter->mac_vlan_list_lock);
711 return;
712 }
713
714 vvfl->vsi_id = adapter->vsi_res->vsi_id;
715 vvfl->num_elements = count;
716 list_for_each_entry_safe(f, ftmp, &adapter->vlan_filter_list, list) {
717 if (f->remove) {
718 vvfl->vlan_id[i] = f->vlan;
719 i++;
720 list_del(&f->list);
721 kfree(f);
722 if (i == count)
723 break;
724 }
725 }
726 if (!more)
727 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_VLAN_FILTER;
728
729 spin_unlock_bh(&adapter->mac_vlan_list_lock);
730
731 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_VLAN, (u8 *)vvfl, len);
732 kfree(vvfl);
733 }
734
735 /**
736 * iavf_set_promiscuous
737 * @adapter: adapter structure
738 * @flags: bitmask to control unicast/multicast promiscuous.
739 *
740 * Request that the PF enable promiscuous mode for our VSI.
741 **/
iavf_set_promiscuous(struct iavf_adapter * adapter,int flags)742 void iavf_set_promiscuous(struct iavf_adapter *adapter, int flags)
743 {
744 struct virtchnl_promisc_info vpi;
745 int promisc_all;
746
747 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
748 /* bail because we already have a command pending */
749 dev_err(&adapter->pdev->dev, "Cannot set promiscuous mode, command %d pending\n",
750 adapter->current_op);
751 return;
752 }
753
754 promisc_all = FLAG_VF_UNICAST_PROMISC |
755 FLAG_VF_MULTICAST_PROMISC;
756 if ((flags & promisc_all) == promisc_all) {
757 adapter->flags |= IAVF_FLAG_PROMISC_ON;
758 adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_PROMISC;
759 dev_info(&adapter->pdev->dev, "Entering promiscuous mode\n");
760 }
761
762 if (flags & FLAG_VF_MULTICAST_PROMISC) {
763 adapter->flags |= IAVF_FLAG_ALLMULTI_ON;
764 adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_ALLMULTI;
765 dev_info(&adapter->pdev->dev, "Entering multicast promiscuous mode\n");
766 }
767
768 if (!flags) {
769 adapter->flags &= ~(IAVF_FLAG_PROMISC_ON |
770 IAVF_FLAG_ALLMULTI_ON);
771 adapter->aq_required &= ~(IAVF_FLAG_AQ_RELEASE_PROMISC |
772 IAVF_FLAG_AQ_RELEASE_ALLMULTI);
773 dev_info(&adapter->pdev->dev, "Leaving promiscuous mode\n");
774 }
775
776 adapter->current_op = VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE;
777 vpi.vsi_id = adapter->vsi_res->vsi_id;
778 vpi.flags = flags;
779 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE,
780 (u8 *)&vpi, sizeof(vpi));
781 }
782
783 /**
784 * iavf_request_stats
785 * @adapter: adapter structure
786 *
787 * Request VSI statistics from PF.
788 **/
iavf_request_stats(struct iavf_adapter * adapter)789 void iavf_request_stats(struct iavf_adapter *adapter)
790 {
791 struct virtchnl_queue_select vqs;
792
793 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
794 /* no error message, this isn't crucial */
795 return;
796 }
797
798 adapter->aq_required &= ~IAVF_FLAG_AQ_REQUEST_STATS;
799 adapter->current_op = VIRTCHNL_OP_GET_STATS;
800 vqs.vsi_id = adapter->vsi_res->vsi_id;
801 /* queue maps are ignored for this message - only the vsi is used */
802 if (iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_STATS, (u8 *)&vqs,
803 sizeof(vqs)))
804 /* if the request failed, don't lock out others */
805 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
806 }
807
808 /**
809 * iavf_get_hena
810 * @adapter: adapter structure
811 *
812 * Request hash enable capabilities from PF
813 **/
iavf_get_hena(struct iavf_adapter * adapter)814 void iavf_get_hena(struct iavf_adapter *adapter)
815 {
816 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
817 /* bail because we already have a command pending */
818 dev_err(&adapter->pdev->dev, "Cannot get RSS hash capabilities, command %d pending\n",
819 adapter->current_op);
820 return;
821 }
822 adapter->current_op = VIRTCHNL_OP_GET_RSS_HENA_CAPS;
823 adapter->aq_required &= ~IAVF_FLAG_AQ_GET_HENA;
824 iavf_send_pf_msg(adapter, VIRTCHNL_OP_GET_RSS_HENA_CAPS, NULL, 0);
825 }
826
827 /**
828 * iavf_set_hena
829 * @adapter: adapter structure
830 *
831 * Request the PF to set our RSS hash capabilities
832 **/
iavf_set_hena(struct iavf_adapter * adapter)833 void iavf_set_hena(struct iavf_adapter *adapter)
834 {
835 struct virtchnl_rss_hena vrh;
836
837 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
838 /* bail because we already have a command pending */
839 dev_err(&adapter->pdev->dev, "Cannot set RSS hash enable, command %d pending\n",
840 adapter->current_op);
841 return;
842 }
843 vrh.hena = adapter->hena;
844 adapter->current_op = VIRTCHNL_OP_SET_RSS_HENA;
845 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_HENA;
846 iavf_send_pf_msg(adapter, VIRTCHNL_OP_SET_RSS_HENA, (u8 *)&vrh,
847 sizeof(vrh));
848 }
849
850 /**
851 * iavf_set_rss_key
852 * @adapter: adapter structure
853 *
854 * Request the PF to set our RSS hash key
855 **/
iavf_set_rss_key(struct iavf_adapter * adapter)856 void iavf_set_rss_key(struct iavf_adapter *adapter)
857 {
858 struct virtchnl_rss_key *vrk;
859 int len;
860
861 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
862 /* bail because we already have a command pending */
863 dev_err(&adapter->pdev->dev, "Cannot set RSS key, command %d pending\n",
864 adapter->current_op);
865 return;
866 }
867 len = sizeof(struct virtchnl_rss_key) +
868 (adapter->rss_key_size * sizeof(u8)) - 1;
869 vrk = kzalloc(len, GFP_KERNEL);
870 if (!vrk)
871 return;
872 vrk->vsi_id = adapter->vsi.id;
873 vrk->key_len = adapter->rss_key_size;
874 memcpy(vrk->key, adapter->rss_key, adapter->rss_key_size);
875
876 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_KEY;
877 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_KEY;
878 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_KEY, (u8 *)vrk, len);
879 kfree(vrk);
880 }
881
882 /**
883 * iavf_set_rss_lut
884 * @adapter: adapter structure
885 *
886 * Request the PF to set our RSS lookup table
887 **/
iavf_set_rss_lut(struct iavf_adapter * adapter)888 void iavf_set_rss_lut(struct iavf_adapter *adapter)
889 {
890 struct virtchnl_rss_lut *vrl;
891 int len;
892
893 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
894 /* bail because we already have a command pending */
895 dev_err(&adapter->pdev->dev, "Cannot set RSS LUT, command %d pending\n",
896 adapter->current_op);
897 return;
898 }
899 len = sizeof(struct virtchnl_rss_lut) +
900 (adapter->rss_lut_size * sizeof(u8)) - 1;
901 vrl = kzalloc(len, GFP_KERNEL);
902 if (!vrl)
903 return;
904 vrl->vsi_id = adapter->vsi.id;
905 vrl->lut_entries = adapter->rss_lut_size;
906 memcpy(vrl->lut, adapter->rss_lut, adapter->rss_lut_size);
907 adapter->current_op = VIRTCHNL_OP_CONFIG_RSS_LUT;
908 adapter->aq_required &= ~IAVF_FLAG_AQ_SET_RSS_LUT;
909 iavf_send_pf_msg(adapter, VIRTCHNL_OP_CONFIG_RSS_LUT, (u8 *)vrl, len);
910 kfree(vrl);
911 }
912
913 /**
914 * iavf_enable_vlan_stripping
915 * @adapter: adapter structure
916 *
917 * Request VLAN header stripping to be enabled
918 **/
iavf_enable_vlan_stripping(struct iavf_adapter * adapter)919 void iavf_enable_vlan_stripping(struct iavf_adapter *adapter)
920 {
921 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
922 /* bail because we already have a command pending */
923 dev_err(&adapter->pdev->dev, "Cannot enable stripping, command %d pending\n",
924 adapter->current_op);
925 return;
926 }
927 adapter->current_op = VIRTCHNL_OP_ENABLE_VLAN_STRIPPING;
928 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_VLAN_STRIPPING;
929 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_VLAN_STRIPPING, NULL, 0);
930 }
931
932 /**
933 * iavf_disable_vlan_stripping
934 * @adapter: adapter structure
935 *
936 * Request VLAN header stripping to be disabled
937 **/
iavf_disable_vlan_stripping(struct iavf_adapter * adapter)938 void iavf_disable_vlan_stripping(struct iavf_adapter *adapter)
939 {
940 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
941 /* bail because we already have a command pending */
942 dev_err(&adapter->pdev->dev, "Cannot disable stripping, command %d pending\n",
943 adapter->current_op);
944 return;
945 }
946 adapter->current_op = VIRTCHNL_OP_DISABLE_VLAN_STRIPPING;
947 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_VLAN_STRIPPING;
948 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING, NULL, 0);
949 }
950
951 #define IAVF_MAX_SPEED_STRLEN 13
952
953 /**
954 * iavf_print_link_message - print link up or down
955 * @adapter: adapter structure
956 *
957 * Log a message telling the world of our wonderous link status
958 */
iavf_print_link_message(struct iavf_adapter * adapter)959 static void iavf_print_link_message(struct iavf_adapter *adapter)
960 {
961 struct net_device *netdev = adapter->netdev;
962 int link_speed_mbps;
963 char *speed;
964
965 if (!adapter->link_up) {
966 netdev_info(netdev, "NIC Link is Down\n");
967 return;
968 }
969
970 speed = kzalloc(IAVF_MAX_SPEED_STRLEN, GFP_KERNEL);
971 if (!speed)
972 return;
973
974 if (ADV_LINK_SUPPORT(adapter)) {
975 link_speed_mbps = adapter->link_speed_mbps;
976 goto print_link_msg;
977 }
978
979 switch (adapter->link_speed) {
980 case VIRTCHNL_LINK_SPEED_40GB:
981 link_speed_mbps = SPEED_40000;
982 break;
983 case VIRTCHNL_LINK_SPEED_25GB:
984 link_speed_mbps = SPEED_25000;
985 break;
986 case VIRTCHNL_LINK_SPEED_20GB:
987 link_speed_mbps = SPEED_20000;
988 break;
989 case VIRTCHNL_LINK_SPEED_10GB:
990 link_speed_mbps = SPEED_10000;
991 break;
992 case VIRTCHNL_LINK_SPEED_5GB:
993 link_speed_mbps = SPEED_5000;
994 break;
995 case VIRTCHNL_LINK_SPEED_2_5GB:
996 link_speed_mbps = SPEED_2500;
997 break;
998 case VIRTCHNL_LINK_SPEED_1GB:
999 link_speed_mbps = SPEED_1000;
1000 break;
1001 case VIRTCHNL_LINK_SPEED_100MB:
1002 link_speed_mbps = SPEED_100;
1003 break;
1004 default:
1005 link_speed_mbps = SPEED_UNKNOWN;
1006 break;
1007 }
1008
1009 print_link_msg:
1010 if (link_speed_mbps > SPEED_1000) {
1011 if (link_speed_mbps == SPEED_2500)
1012 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "2.5 Gbps");
1013 else
1014 /* convert to Gbps inline */
1015 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%d %s",
1016 link_speed_mbps / 1000, "Gbps");
1017 } else if (link_speed_mbps == SPEED_UNKNOWN) {
1018 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%s", "Unknown Mbps");
1019 } else {
1020 snprintf(speed, IAVF_MAX_SPEED_STRLEN, "%u %s",
1021 link_speed_mbps, "Mbps");
1022 }
1023
1024 netdev_info(netdev, "NIC Link is Up Speed is %s Full Duplex\n", speed);
1025 kfree(speed);
1026 }
1027
1028 /**
1029 * iavf_get_vpe_link_status
1030 * @adapter: adapter structure
1031 * @vpe: virtchnl_pf_event structure
1032 *
1033 * Helper function for determining the link status
1034 **/
1035 static bool
iavf_get_vpe_link_status(struct iavf_adapter * adapter,struct virtchnl_pf_event * vpe)1036 iavf_get_vpe_link_status(struct iavf_adapter *adapter,
1037 struct virtchnl_pf_event *vpe)
1038 {
1039 if (ADV_LINK_SUPPORT(adapter))
1040 return vpe->event_data.link_event_adv.link_status;
1041 else
1042 return vpe->event_data.link_event.link_status;
1043 }
1044
1045 /**
1046 * iavf_set_adapter_link_speed_from_vpe
1047 * @adapter: adapter structure for which we are setting the link speed
1048 * @vpe: virtchnl_pf_event structure that contains the link speed we are setting
1049 *
1050 * Helper function for setting iavf_adapter link speed
1051 **/
1052 static void
iavf_set_adapter_link_speed_from_vpe(struct iavf_adapter * adapter,struct virtchnl_pf_event * vpe)1053 iavf_set_adapter_link_speed_from_vpe(struct iavf_adapter *adapter,
1054 struct virtchnl_pf_event *vpe)
1055 {
1056 if (ADV_LINK_SUPPORT(adapter))
1057 adapter->link_speed_mbps =
1058 vpe->event_data.link_event_adv.link_speed;
1059 else
1060 adapter->link_speed = vpe->event_data.link_event.link_speed;
1061 }
1062
1063 /**
1064 * iavf_enable_channels
1065 * @adapter: adapter structure
1066 *
1067 * Request that the PF enable channels as specified by
1068 * the user via tc tool.
1069 **/
iavf_enable_channels(struct iavf_adapter * adapter)1070 void iavf_enable_channels(struct iavf_adapter *adapter)
1071 {
1072 struct virtchnl_tc_info *vti = NULL;
1073 size_t len;
1074 int i;
1075
1076 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1077 /* bail because we already have a command pending */
1078 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1079 adapter->current_op);
1080 return;
1081 }
1082
1083 len = struct_size(vti, list, adapter->num_tc - 1);
1084 vti = kzalloc(len, GFP_KERNEL);
1085 if (!vti)
1086 return;
1087 vti->num_tc = adapter->num_tc;
1088 for (i = 0; i < vti->num_tc; i++) {
1089 vti->list[i].count = adapter->ch_config.ch_info[i].count;
1090 vti->list[i].offset = adapter->ch_config.ch_info[i].offset;
1091 vti->list[i].pad = 0;
1092 vti->list[i].max_tx_rate =
1093 adapter->ch_config.ch_info[i].max_tx_rate;
1094 }
1095
1096 adapter->ch_config.state = __IAVF_TC_RUNNING;
1097 adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1098 adapter->current_op = VIRTCHNL_OP_ENABLE_CHANNELS;
1099 adapter->aq_required &= ~IAVF_FLAG_AQ_ENABLE_CHANNELS;
1100 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ENABLE_CHANNELS, (u8 *)vti, len);
1101 kfree(vti);
1102 }
1103
1104 /**
1105 * iavf_disable_channels
1106 * @adapter: adapter structure
1107 *
1108 * Request that the PF disable channels that are configured
1109 **/
iavf_disable_channels(struct iavf_adapter * adapter)1110 void iavf_disable_channels(struct iavf_adapter *adapter)
1111 {
1112 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1113 /* bail because we already have a command pending */
1114 dev_err(&adapter->pdev->dev, "Cannot configure mqprio, command %d pending\n",
1115 adapter->current_op);
1116 return;
1117 }
1118
1119 adapter->ch_config.state = __IAVF_TC_INVALID;
1120 adapter->flags |= IAVF_FLAG_REINIT_ITR_NEEDED;
1121 adapter->current_op = VIRTCHNL_OP_DISABLE_CHANNELS;
1122 adapter->aq_required &= ~IAVF_FLAG_AQ_DISABLE_CHANNELS;
1123 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DISABLE_CHANNELS, NULL, 0);
1124 }
1125
1126 /**
1127 * iavf_print_cloud_filter
1128 * @adapter: adapter structure
1129 * @f: cloud filter to print
1130 *
1131 * Print the cloud filter
1132 **/
iavf_print_cloud_filter(struct iavf_adapter * adapter,struct virtchnl_filter * f)1133 static void iavf_print_cloud_filter(struct iavf_adapter *adapter,
1134 struct virtchnl_filter *f)
1135 {
1136 switch (f->flow_type) {
1137 case VIRTCHNL_TCP_V4_FLOW:
1138 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",
1139 &f->data.tcp_spec.dst_mac,
1140 &f->data.tcp_spec.src_mac,
1141 ntohs(f->data.tcp_spec.vlan_id),
1142 &f->data.tcp_spec.dst_ip[0],
1143 &f->data.tcp_spec.src_ip[0],
1144 ntohs(f->data.tcp_spec.dst_port),
1145 ntohs(f->data.tcp_spec.src_port));
1146 break;
1147 case VIRTCHNL_TCP_V6_FLOW:
1148 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",
1149 &f->data.tcp_spec.dst_mac,
1150 &f->data.tcp_spec.src_mac,
1151 ntohs(f->data.tcp_spec.vlan_id),
1152 &f->data.tcp_spec.dst_ip,
1153 &f->data.tcp_spec.src_ip,
1154 ntohs(f->data.tcp_spec.dst_port),
1155 ntohs(f->data.tcp_spec.src_port));
1156 break;
1157 }
1158 }
1159
1160 /**
1161 * iavf_add_cloud_filter
1162 * @adapter: adapter structure
1163 *
1164 * Request that the PF add cloud filters as specified
1165 * by the user via tc tool.
1166 **/
iavf_add_cloud_filter(struct iavf_adapter * adapter)1167 void iavf_add_cloud_filter(struct iavf_adapter *adapter)
1168 {
1169 struct iavf_cloud_filter *cf;
1170 struct virtchnl_filter *f;
1171 int len = 0, count = 0;
1172
1173 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1174 /* bail because we already have a command pending */
1175 dev_err(&adapter->pdev->dev, "Cannot add cloud filter, command %d pending\n",
1176 adapter->current_op);
1177 return;
1178 }
1179 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1180 if (cf->add) {
1181 count++;
1182 break;
1183 }
1184 }
1185 if (!count) {
1186 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_CLOUD_FILTER;
1187 return;
1188 }
1189 adapter->current_op = VIRTCHNL_OP_ADD_CLOUD_FILTER;
1190
1191 len = sizeof(struct virtchnl_filter);
1192 f = kzalloc(len, GFP_KERNEL);
1193 if (!f)
1194 return;
1195
1196 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1197 if (cf->add) {
1198 memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1199 cf->add = false;
1200 cf->state = __IAVF_CF_ADD_PENDING;
1201 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_CLOUD_FILTER,
1202 (u8 *)f, len);
1203 }
1204 }
1205 kfree(f);
1206 }
1207
1208 /**
1209 * iavf_del_cloud_filter
1210 * @adapter: adapter structure
1211 *
1212 * Request that the PF delete cloud filters as specified
1213 * by the user via tc tool.
1214 **/
iavf_del_cloud_filter(struct iavf_adapter * adapter)1215 void iavf_del_cloud_filter(struct iavf_adapter *adapter)
1216 {
1217 struct iavf_cloud_filter *cf, *cftmp;
1218 struct virtchnl_filter *f;
1219 int len = 0, count = 0;
1220
1221 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1222 /* bail because we already have a command pending */
1223 dev_err(&adapter->pdev->dev, "Cannot remove cloud filter, command %d pending\n",
1224 adapter->current_op);
1225 return;
1226 }
1227 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1228 if (cf->del) {
1229 count++;
1230 break;
1231 }
1232 }
1233 if (!count) {
1234 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_CLOUD_FILTER;
1235 return;
1236 }
1237 adapter->current_op = VIRTCHNL_OP_DEL_CLOUD_FILTER;
1238
1239 len = sizeof(struct virtchnl_filter);
1240 f = kzalloc(len, GFP_KERNEL);
1241 if (!f)
1242 return;
1243
1244 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list, list) {
1245 if (cf->del) {
1246 memcpy(f, &cf->f, sizeof(struct virtchnl_filter));
1247 cf->del = false;
1248 cf->state = __IAVF_CF_DEL_PENDING;
1249 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_CLOUD_FILTER,
1250 (u8 *)f, len);
1251 }
1252 }
1253 kfree(f);
1254 }
1255
1256 /**
1257 * iavf_add_fdir_filter
1258 * @adapter: the VF adapter structure
1259 *
1260 * Request that the PF add Flow Director filters as specified
1261 * by the user via ethtool.
1262 **/
iavf_add_fdir_filter(struct iavf_adapter * adapter)1263 void iavf_add_fdir_filter(struct iavf_adapter *adapter)
1264 {
1265 struct iavf_fdir_fltr *fdir;
1266 struct virtchnl_fdir_add *f;
1267 bool process_fltr = false;
1268 int len;
1269
1270 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1271 /* bail because we already have a command pending */
1272 dev_err(&adapter->pdev->dev, "Cannot add Flow Director filter, command %d pending\n",
1273 adapter->current_op);
1274 return;
1275 }
1276
1277 len = sizeof(struct virtchnl_fdir_add);
1278 f = kzalloc(len, GFP_KERNEL);
1279 if (!f)
1280 return;
1281
1282 spin_lock_bh(&adapter->fdir_fltr_lock);
1283 list_for_each_entry(fdir, &adapter->fdir_list_head, list) {
1284 if (fdir->state == IAVF_FDIR_FLTR_ADD_REQUEST) {
1285 process_fltr = true;
1286 fdir->state = IAVF_FDIR_FLTR_ADD_PENDING;
1287 memcpy(f, &fdir->vc_add_msg, len);
1288 break;
1289 }
1290 }
1291 spin_unlock_bh(&adapter->fdir_fltr_lock);
1292
1293 if (!process_fltr) {
1294 /* prevent iavf_add_fdir_filter() from being called when there
1295 * are no filters to add
1296 */
1297 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_FDIR_FILTER;
1298 kfree(f);
1299 return;
1300 }
1301 adapter->current_op = VIRTCHNL_OP_ADD_FDIR_FILTER;
1302 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_FDIR_FILTER, (u8 *)f, len);
1303 kfree(f);
1304 }
1305
1306 /**
1307 * iavf_del_fdir_filter
1308 * @adapter: the VF adapter structure
1309 *
1310 * Request that the PF delete Flow Director filters as specified
1311 * by the user via ethtool.
1312 **/
iavf_del_fdir_filter(struct iavf_adapter * adapter)1313 void iavf_del_fdir_filter(struct iavf_adapter *adapter)
1314 {
1315 struct iavf_fdir_fltr *fdir;
1316 struct virtchnl_fdir_del f;
1317 bool process_fltr = false;
1318 int len;
1319
1320 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1321 /* bail because we already have a command pending */
1322 dev_err(&adapter->pdev->dev, "Cannot remove Flow Director filter, command %d pending\n",
1323 adapter->current_op);
1324 return;
1325 }
1326
1327 len = sizeof(struct virtchnl_fdir_del);
1328
1329 spin_lock_bh(&adapter->fdir_fltr_lock);
1330 list_for_each_entry(fdir, &adapter->fdir_list_head, list) {
1331 if (fdir->state == IAVF_FDIR_FLTR_DEL_REQUEST) {
1332 process_fltr = true;
1333 memset(&f, 0, len);
1334 f.vsi_id = fdir->vc_add_msg.vsi_id;
1335 f.flow_id = fdir->flow_id;
1336 fdir->state = IAVF_FDIR_FLTR_DEL_PENDING;
1337 break;
1338 }
1339 }
1340 spin_unlock_bh(&adapter->fdir_fltr_lock);
1341
1342 if (!process_fltr) {
1343 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_FDIR_FILTER;
1344 return;
1345 }
1346
1347 adapter->current_op = VIRTCHNL_OP_DEL_FDIR_FILTER;
1348 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_FDIR_FILTER, (u8 *)&f, len);
1349 }
1350
1351 /**
1352 * iavf_add_adv_rss_cfg
1353 * @adapter: the VF adapter structure
1354 *
1355 * Request that the PF add RSS configuration as specified
1356 * by the user via ethtool.
1357 **/
iavf_add_adv_rss_cfg(struct iavf_adapter * adapter)1358 void iavf_add_adv_rss_cfg(struct iavf_adapter *adapter)
1359 {
1360 struct virtchnl_rss_cfg *rss_cfg;
1361 struct iavf_adv_rss *rss;
1362 bool process_rss = false;
1363 int len;
1364
1365 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1366 /* bail because we already have a command pending */
1367 dev_err(&adapter->pdev->dev, "Cannot add RSS configuration, command %d pending\n",
1368 adapter->current_op);
1369 return;
1370 }
1371
1372 len = sizeof(struct virtchnl_rss_cfg);
1373 rss_cfg = kzalloc(len, GFP_KERNEL);
1374 if (!rss_cfg)
1375 return;
1376
1377 spin_lock_bh(&adapter->adv_rss_lock);
1378 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
1379 if (rss->state == IAVF_ADV_RSS_ADD_REQUEST) {
1380 process_rss = true;
1381 rss->state = IAVF_ADV_RSS_ADD_PENDING;
1382 memcpy(rss_cfg, &rss->cfg_msg, len);
1383 iavf_print_adv_rss_cfg(adapter, rss,
1384 "Input set change for",
1385 "is pending");
1386 break;
1387 }
1388 }
1389 spin_unlock_bh(&adapter->adv_rss_lock);
1390
1391 if (process_rss) {
1392 adapter->current_op = VIRTCHNL_OP_ADD_RSS_CFG;
1393 iavf_send_pf_msg(adapter, VIRTCHNL_OP_ADD_RSS_CFG,
1394 (u8 *)rss_cfg, len);
1395 } else {
1396 adapter->aq_required &= ~IAVF_FLAG_AQ_ADD_ADV_RSS_CFG;
1397 }
1398
1399 kfree(rss_cfg);
1400 }
1401
1402 /**
1403 * iavf_del_adv_rss_cfg
1404 * @adapter: the VF adapter structure
1405 *
1406 * Request that the PF delete RSS configuration as specified
1407 * by the user via ethtool.
1408 **/
iavf_del_adv_rss_cfg(struct iavf_adapter * adapter)1409 void iavf_del_adv_rss_cfg(struct iavf_adapter *adapter)
1410 {
1411 struct virtchnl_rss_cfg *rss_cfg;
1412 struct iavf_adv_rss *rss;
1413 bool process_rss = false;
1414 int len;
1415
1416 if (adapter->current_op != VIRTCHNL_OP_UNKNOWN) {
1417 /* bail because we already have a command pending */
1418 dev_err(&adapter->pdev->dev, "Cannot remove RSS configuration, command %d pending\n",
1419 adapter->current_op);
1420 return;
1421 }
1422
1423 len = sizeof(struct virtchnl_rss_cfg);
1424 rss_cfg = kzalloc(len, GFP_KERNEL);
1425 if (!rss_cfg)
1426 return;
1427
1428 spin_lock_bh(&adapter->adv_rss_lock);
1429 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
1430 if (rss->state == IAVF_ADV_RSS_DEL_REQUEST) {
1431 process_rss = true;
1432 rss->state = IAVF_ADV_RSS_DEL_PENDING;
1433 memcpy(rss_cfg, &rss->cfg_msg, len);
1434 break;
1435 }
1436 }
1437 spin_unlock_bh(&adapter->adv_rss_lock);
1438
1439 if (process_rss) {
1440 adapter->current_op = VIRTCHNL_OP_DEL_RSS_CFG;
1441 iavf_send_pf_msg(adapter, VIRTCHNL_OP_DEL_RSS_CFG,
1442 (u8 *)rss_cfg, len);
1443 } else {
1444 adapter->aq_required &= ~IAVF_FLAG_AQ_DEL_ADV_RSS_CFG;
1445 }
1446
1447 kfree(rss_cfg);
1448 }
1449
1450 /**
1451 * iavf_request_reset
1452 * @adapter: adapter structure
1453 *
1454 * Request that the PF reset this VF. No response is expected.
1455 **/
iavf_request_reset(struct iavf_adapter * adapter)1456 void iavf_request_reset(struct iavf_adapter *adapter)
1457 {
1458 /* Don't check CURRENT_OP - this is always higher priority */
1459 iavf_send_pf_msg(adapter, VIRTCHNL_OP_RESET_VF, NULL, 0);
1460 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1461 }
1462
1463 /**
1464 * iavf_virtchnl_completion
1465 * @adapter: adapter structure
1466 * @v_opcode: opcode sent by PF
1467 * @v_retval: retval sent by PF
1468 * @msg: message sent by PF
1469 * @msglen: message length
1470 *
1471 * Asynchronous completion function for admin queue messages. Rather than busy
1472 * wait, we fire off our requests and assume that no errors will be returned.
1473 * This function handles the reply messages.
1474 **/
iavf_virtchnl_completion(struct iavf_adapter * adapter,enum virtchnl_ops v_opcode,enum iavf_status v_retval,u8 * msg,u16 msglen)1475 void iavf_virtchnl_completion(struct iavf_adapter *adapter,
1476 enum virtchnl_ops v_opcode,
1477 enum iavf_status v_retval, u8 *msg, u16 msglen)
1478 {
1479 struct net_device *netdev = adapter->netdev;
1480
1481 if (v_opcode == VIRTCHNL_OP_EVENT) {
1482 struct virtchnl_pf_event *vpe =
1483 (struct virtchnl_pf_event *)msg;
1484 bool link_up = iavf_get_vpe_link_status(adapter, vpe);
1485
1486 switch (vpe->event) {
1487 case VIRTCHNL_EVENT_LINK_CHANGE:
1488 iavf_set_adapter_link_speed_from_vpe(adapter, vpe);
1489
1490 /* we've already got the right link status, bail */
1491 if (adapter->link_up == link_up)
1492 break;
1493
1494 if (link_up) {
1495 /* If we get link up message and start queues
1496 * before our queues are configured it will
1497 * trigger a TX hang. In that case, just ignore
1498 * the link status message,we'll get another one
1499 * after we enable queues and actually prepared
1500 * to send traffic.
1501 */
1502 if (adapter->state != __IAVF_RUNNING)
1503 break;
1504
1505 /* For ADq enabled VF, we reconfigure VSIs and
1506 * re-allocate queues. Hence wait till all
1507 * queues are enabled.
1508 */
1509 if (adapter->flags &
1510 IAVF_FLAG_QUEUES_DISABLED)
1511 break;
1512 }
1513
1514 adapter->link_up = link_up;
1515 if (link_up) {
1516 netif_tx_start_all_queues(netdev);
1517 netif_carrier_on(netdev);
1518 } else {
1519 netif_tx_stop_all_queues(netdev);
1520 netif_carrier_off(netdev);
1521 }
1522 iavf_print_link_message(adapter);
1523 break;
1524 case VIRTCHNL_EVENT_RESET_IMPENDING:
1525 dev_info(&adapter->pdev->dev, "Reset warning received from the PF\n");
1526 if (!(adapter->flags & IAVF_FLAG_RESET_PENDING)) {
1527 adapter->flags |= IAVF_FLAG_RESET_PENDING;
1528 dev_info(&adapter->pdev->dev, "Scheduling reset task\n");
1529 queue_work(iavf_wq, &adapter->reset_task);
1530 }
1531 break;
1532 default:
1533 dev_err(&adapter->pdev->dev, "Unknown event %d from PF\n",
1534 vpe->event);
1535 break;
1536 }
1537 return;
1538 }
1539 if (v_retval) {
1540 switch (v_opcode) {
1541 case VIRTCHNL_OP_ADD_VLAN:
1542 dev_err(&adapter->pdev->dev, "Failed to add VLAN filter, error %s\n",
1543 iavf_stat_str(&adapter->hw, v_retval));
1544 break;
1545 case VIRTCHNL_OP_ADD_ETH_ADDR:
1546 dev_err(&adapter->pdev->dev, "Failed to add MAC filter, error %s\n",
1547 iavf_stat_str(&adapter->hw, v_retval));
1548 iavf_mac_add_reject(adapter);
1549 /* restore administratively set MAC address */
1550 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
1551 break;
1552 case VIRTCHNL_OP_DEL_VLAN:
1553 dev_err(&adapter->pdev->dev, "Failed to delete VLAN filter, error %s\n",
1554 iavf_stat_str(&adapter->hw, v_retval));
1555 break;
1556 case VIRTCHNL_OP_DEL_ETH_ADDR:
1557 dev_err(&adapter->pdev->dev, "Failed to delete MAC filter, error %s\n",
1558 iavf_stat_str(&adapter->hw, v_retval));
1559 break;
1560 case VIRTCHNL_OP_ENABLE_CHANNELS:
1561 dev_err(&adapter->pdev->dev, "Failed to configure queue channels, error %s\n",
1562 iavf_stat_str(&adapter->hw, v_retval));
1563 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
1564 adapter->ch_config.state = __IAVF_TC_INVALID;
1565 netdev_reset_tc(netdev);
1566 netif_tx_start_all_queues(netdev);
1567 break;
1568 case VIRTCHNL_OP_DISABLE_CHANNELS:
1569 dev_err(&adapter->pdev->dev, "Failed to disable queue channels, error %s\n",
1570 iavf_stat_str(&adapter->hw, v_retval));
1571 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
1572 adapter->ch_config.state = __IAVF_TC_RUNNING;
1573 netif_tx_start_all_queues(netdev);
1574 break;
1575 case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
1576 struct iavf_cloud_filter *cf, *cftmp;
1577
1578 list_for_each_entry_safe(cf, cftmp,
1579 &adapter->cloud_filter_list,
1580 list) {
1581 if (cf->state == __IAVF_CF_ADD_PENDING) {
1582 cf->state = __IAVF_CF_INVALID;
1583 dev_info(&adapter->pdev->dev, "Failed to add cloud filter, error %s\n",
1584 iavf_stat_str(&adapter->hw,
1585 v_retval));
1586 iavf_print_cloud_filter(adapter,
1587 &cf->f);
1588 list_del(&cf->list);
1589 kfree(cf);
1590 adapter->num_cloud_filters--;
1591 }
1592 }
1593 }
1594 break;
1595 case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
1596 struct iavf_cloud_filter *cf;
1597
1598 list_for_each_entry(cf, &adapter->cloud_filter_list,
1599 list) {
1600 if (cf->state == __IAVF_CF_DEL_PENDING) {
1601 cf->state = __IAVF_CF_ACTIVE;
1602 dev_info(&adapter->pdev->dev, "Failed to del cloud filter, error %s\n",
1603 iavf_stat_str(&adapter->hw,
1604 v_retval));
1605 iavf_print_cloud_filter(adapter,
1606 &cf->f);
1607 }
1608 }
1609 }
1610 break;
1611 case VIRTCHNL_OP_ADD_FDIR_FILTER: {
1612 struct iavf_fdir_fltr *fdir, *fdir_tmp;
1613
1614 spin_lock_bh(&adapter->fdir_fltr_lock);
1615 list_for_each_entry_safe(fdir, fdir_tmp,
1616 &adapter->fdir_list_head,
1617 list) {
1618 if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) {
1619 dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter, error %s\n",
1620 iavf_stat_str(&adapter->hw,
1621 v_retval));
1622 iavf_print_fdir_fltr(adapter, fdir);
1623 if (msglen)
1624 dev_err(&adapter->pdev->dev,
1625 "%s\n", msg);
1626 list_del(&fdir->list);
1627 kfree(fdir);
1628 adapter->fdir_active_fltr--;
1629 }
1630 }
1631 spin_unlock_bh(&adapter->fdir_fltr_lock);
1632 }
1633 break;
1634 case VIRTCHNL_OP_DEL_FDIR_FILTER: {
1635 struct iavf_fdir_fltr *fdir;
1636
1637 spin_lock_bh(&adapter->fdir_fltr_lock);
1638 list_for_each_entry(fdir, &adapter->fdir_list_head,
1639 list) {
1640 if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING) {
1641 fdir->state = IAVF_FDIR_FLTR_ACTIVE;
1642 dev_info(&adapter->pdev->dev, "Failed to del Flow Director filter, error %s\n",
1643 iavf_stat_str(&adapter->hw,
1644 v_retval));
1645 iavf_print_fdir_fltr(adapter, fdir);
1646 }
1647 }
1648 spin_unlock_bh(&adapter->fdir_fltr_lock);
1649 }
1650 break;
1651 case VIRTCHNL_OP_ADD_RSS_CFG: {
1652 struct iavf_adv_rss *rss, *rss_tmp;
1653
1654 spin_lock_bh(&adapter->adv_rss_lock);
1655 list_for_each_entry_safe(rss, rss_tmp,
1656 &adapter->adv_rss_list_head,
1657 list) {
1658 if (rss->state == IAVF_ADV_RSS_ADD_PENDING) {
1659 iavf_print_adv_rss_cfg(adapter, rss,
1660 "Failed to change the input set for",
1661 NULL);
1662 list_del(&rss->list);
1663 kfree(rss);
1664 }
1665 }
1666 spin_unlock_bh(&adapter->adv_rss_lock);
1667 }
1668 break;
1669 case VIRTCHNL_OP_DEL_RSS_CFG: {
1670 struct iavf_adv_rss *rss;
1671
1672 spin_lock_bh(&adapter->adv_rss_lock);
1673 list_for_each_entry(rss, &adapter->adv_rss_list_head,
1674 list) {
1675 if (rss->state == IAVF_ADV_RSS_DEL_PENDING) {
1676 rss->state = IAVF_ADV_RSS_ACTIVE;
1677 dev_err(&adapter->pdev->dev, "Failed to delete RSS configuration, error %s\n",
1678 iavf_stat_str(&adapter->hw,
1679 v_retval));
1680 }
1681 }
1682 spin_unlock_bh(&adapter->adv_rss_lock);
1683 }
1684 break;
1685 case VIRTCHNL_OP_ENABLE_VLAN_STRIPPING:
1686 case VIRTCHNL_OP_DISABLE_VLAN_STRIPPING:
1687 dev_warn(&adapter->pdev->dev, "Changing VLAN Stripping is not allowed when Port VLAN is configured\n");
1688 break;
1689 default:
1690 dev_err(&adapter->pdev->dev, "PF returned error %d (%s) to our request %d\n",
1691 v_retval, iavf_stat_str(&adapter->hw, v_retval),
1692 v_opcode);
1693 }
1694 }
1695 switch (v_opcode) {
1696 case VIRTCHNL_OP_ADD_ETH_ADDR:
1697 if (!v_retval)
1698 iavf_mac_add_ok(adapter);
1699 if (!ether_addr_equal(netdev->dev_addr, adapter->hw.mac.addr))
1700 eth_hw_addr_set(netdev, adapter->hw.mac.addr);
1701 break;
1702 case VIRTCHNL_OP_GET_STATS: {
1703 struct iavf_eth_stats *stats =
1704 (struct iavf_eth_stats *)msg;
1705 netdev->stats.rx_packets = stats->rx_unicast +
1706 stats->rx_multicast +
1707 stats->rx_broadcast;
1708 netdev->stats.tx_packets = stats->tx_unicast +
1709 stats->tx_multicast +
1710 stats->tx_broadcast;
1711 netdev->stats.rx_bytes = stats->rx_bytes;
1712 netdev->stats.tx_bytes = stats->tx_bytes;
1713 netdev->stats.tx_errors = stats->tx_errors;
1714 netdev->stats.rx_dropped = stats->rx_discards;
1715 netdev->stats.tx_dropped = stats->tx_discards;
1716 adapter->current_stats = *stats;
1717 }
1718 break;
1719 case VIRTCHNL_OP_GET_VF_RESOURCES: {
1720 u16 len = sizeof(struct virtchnl_vf_resource) +
1721 IAVF_MAX_VF_VSI *
1722 sizeof(struct virtchnl_vsi_resource);
1723 memcpy(adapter->vf_res, msg, min(msglen, len));
1724 iavf_validate_num_queues(adapter);
1725 iavf_vf_parse_hw_config(&adapter->hw, adapter->vf_res);
1726 if (is_zero_ether_addr(adapter->hw.mac.addr)) {
1727 /* restore current mac address */
1728 ether_addr_copy(adapter->hw.mac.addr, netdev->dev_addr);
1729 } else {
1730 /* refresh current mac address if changed */
1731 eth_hw_addr_set(netdev, adapter->hw.mac.addr);
1732 ether_addr_copy(netdev->perm_addr,
1733 adapter->hw.mac.addr);
1734 }
1735 spin_lock_bh(&adapter->mac_vlan_list_lock);
1736 iavf_add_filter(adapter, adapter->hw.mac.addr);
1737
1738 if (VLAN_ALLOWED(adapter)) {
1739 if (!list_empty(&adapter->vlan_filter_list)) {
1740 struct iavf_vlan_filter *vlf;
1741
1742 /* re-add all VLAN filters over virtchnl */
1743 list_for_each_entry(vlf,
1744 &adapter->vlan_filter_list,
1745 list)
1746 vlf->add = true;
1747
1748 adapter->aq_required |=
1749 IAVF_FLAG_AQ_ADD_VLAN_FILTER;
1750 }
1751 }
1752
1753 spin_unlock_bh(&adapter->mac_vlan_list_lock);
1754 iavf_process_config(adapter);
1755
1756 /* unlock crit_lock before acquiring rtnl_lock as other
1757 * processes holding rtnl_lock could be waiting for the same
1758 * crit_lock
1759 */
1760 mutex_unlock(&adapter->crit_lock);
1761 rtnl_lock();
1762 netdev_update_features(adapter->netdev);
1763 rtnl_unlock();
1764 if (iavf_lock_timeout(&adapter->crit_lock, 10000))
1765 dev_warn(&adapter->pdev->dev, "failed to acquire crit_lock in %s\n",
1766 __FUNCTION__);
1767
1768 }
1769 break;
1770 case VIRTCHNL_OP_ENABLE_QUEUES:
1771 /* enable transmits */
1772 iavf_irq_enable(adapter, true);
1773 adapter->flags &= ~IAVF_FLAG_QUEUES_DISABLED;
1774 break;
1775 case VIRTCHNL_OP_DISABLE_QUEUES:
1776 iavf_free_all_tx_resources(adapter);
1777 iavf_free_all_rx_resources(adapter);
1778 if (adapter->state == __IAVF_DOWN_PENDING) {
1779 iavf_change_state(adapter, __IAVF_DOWN);
1780 wake_up(&adapter->down_waitqueue);
1781 }
1782 break;
1783 case VIRTCHNL_OP_VERSION:
1784 case VIRTCHNL_OP_CONFIG_IRQ_MAP:
1785 /* Don't display an error if we get these out of sequence.
1786 * If the firmware needed to get kicked, we'll get these and
1787 * it's no problem.
1788 */
1789 if (v_opcode != adapter->current_op)
1790 return;
1791 break;
1792 case VIRTCHNL_OP_IWARP:
1793 /* Gobble zero-length replies from the PF. They indicate that
1794 * a previous message was received OK, and the client doesn't
1795 * care about that.
1796 */
1797 if (msglen && CLIENT_ENABLED(adapter))
1798 iavf_notify_client_message(&adapter->vsi, msg, msglen);
1799 break;
1800
1801 case VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP:
1802 adapter->client_pending &=
1803 ~(BIT(VIRTCHNL_OP_CONFIG_IWARP_IRQ_MAP));
1804 break;
1805 case VIRTCHNL_OP_GET_RSS_HENA_CAPS: {
1806 struct virtchnl_rss_hena *vrh = (struct virtchnl_rss_hena *)msg;
1807
1808 if (msglen == sizeof(*vrh))
1809 adapter->hena = vrh->hena;
1810 else
1811 dev_warn(&adapter->pdev->dev,
1812 "Invalid message %d from PF\n", v_opcode);
1813 }
1814 break;
1815 case VIRTCHNL_OP_REQUEST_QUEUES: {
1816 struct virtchnl_vf_res_request *vfres =
1817 (struct virtchnl_vf_res_request *)msg;
1818
1819 if (vfres->num_queue_pairs != adapter->num_req_queues) {
1820 dev_info(&adapter->pdev->dev,
1821 "Requested %d queues, PF can support %d\n",
1822 adapter->num_req_queues,
1823 vfres->num_queue_pairs);
1824 adapter->num_req_queues = 0;
1825 adapter->flags &= ~IAVF_FLAG_REINIT_ITR_NEEDED;
1826 }
1827 }
1828 break;
1829 case VIRTCHNL_OP_ADD_CLOUD_FILTER: {
1830 struct iavf_cloud_filter *cf;
1831
1832 list_for_each_entry(cf, &adapter->cloud_filter_list, list) {
1833 if (cf->state == __IAVF_CF_ADD_PENDING)
1834 cf->state = __IAVF_CF_ACTIVE;
1835 }
1836 }
1837 break;
1838 case VIRTCHNL_OP_DEL_CLOUD_FILTER: {
1839 struct iavf_cloud_filter *cf, *cftmp;
1840
1841 list_for_each_entry_safe(cf, cftmp, &adapter->cloud_filter_list,
1842 list) {
1843 if (cf->state == __IAVF_CF_DEL_PENDING) {
1844 cf->state = __IAVF_CF_INVALID;
1845 list_del(&cf->list);
1846 kfree(cf);
1847 adapter->num_cloud_filters--;
1848 }
1849 }
1850 }
1851 break;
1852 case VIRTCHNL_OP_ADD_FDIR_FILTER: {
1853 struct virtchnl_fdir_add *add_fltr = (struct virtchnl_fdir_add *)msg;
1854 struct iavf_fdir_fltr *fdir, *fdir_tmp;
1855
1856 spin_lock_bh(&adapter->fdir_fltr_lock);
1857 list_for_each_entry_safe(fdir, fdir_tmp,
1858 &adapter->fdir_list_head,
1859 list) {
1860 if (fdir->state == IAVF_FDIR_FLTR_ADD_PENDING) {
1861 if (add_fltr->status == VIRTCHNL_FDIR_SUCCESS) {
1862 dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is added\n",
1863 fdir->loc);
1864 fdir->state = IAVF_FDIR_FLTR_ACTIVE;
1865 fdir->flow_id = add_fltr->flow_id;
1866 } else {
1867 dev_info(&adapter->pdev->dev, "Failed to add Flow Director filter with status: %d\n",
1868 add_fltr->status);
1869 iavf_print_fdir_fltr(adapter, fdir);
1870 list_del(&fdir->list);
1871 kfree(fdir);
1872 adapter->fdir_active_fltr--;
1873 }
1874 }
1875 }
1876 spin_unlock_bh(&adapter->fdir_fltr_lock);
1877 }
1878 break;
1879 case VIRTCHNL_OP_DEL_FDIR_FILTER: {
1880 struct virtchnl_fdir_del *del_fltr = (struct virtchnl_fdir_del *)msg;
1881 struct iavf_fdir_fltr *fdir, *fdir_tmp;
1882
1883 spin_lock_bh(&adapter->fdir_fltr_lock);
1884 list_for_each_entry_safe(fdir, fdir_tmp, &adapter->fdir_list_head,
1885 list) {
1886 if (fdir->state == IAVF_FDIR_FLTR_DEL_PENDING) {
1887 if (del_fltr->status == VIRTCHNL_FDIR_SUCCESS) {
1888 dev_info(&adapter->pdev->dev, "Flow Director filter with location %u is deleted\n",
1889 fdir->loc);
1890 list_del(&fdir->list);
1891 kfree(fdir);
1892 adapter->fdir_active_fltr--;
1893 } else {
1894 fdir->state = IAVF_FDIR_FLTR_ACTIVE;
1895 dev_info(&adapter->pdev->dev, "Failed to delete Flow Director filter with status: %d\n",
1896 del_fltr->status);
1897 iavf_print_fdir_fltr(adapter, fdir);
1898 }
1899 }
1900 }
1901 spin_unlock_bh(&adapter->fdir_fltr_lock);
1902 }
1903 break;
1904 case VIRTCHNL_OP_ADD_RSS_CFG: {
1905 struct iavf_adv_rss *rss;
1906
1907 spin_lock_bh(&adapter->adv_rss_lock);
1908 list_for_each_entry(rss, &adapter->adv_rss_list_head, list) {
1909 if (rss->state == IAVF_ADV_RSS_ADD_PENDING) {
1910 iavf_print_adv_rss_cfg(adapter, rss,
1911 "Input set change for",
1912 "successful");
1913 rss->state = IAVF_ADV_RSS_ACTIVE;
1914 }
1915 }
1916 spin_unlock_bh(&adapter->adv_rss_lock);
1917 }
1918 break;
1919 case VIRTCHNL_OP_DEL_RSS_CFG: {
1920 struct iavf_adv_rss *rss, *rss_tmp;
1921
1922 spin_lock_bh(&adapter->adv_rss_lock);
1923 list_for_each_entry_safe(rss, rss_tmp,
1924 &adapter->adv_rss_list_head, list) {
1925 if (rss->state == IAVF_ADV_RSS_DEL_PENDING) {
1926 list_del(&rss->list);
1927 kfree(rss);
1928 }
1929 }
1930 spin_unlock_bh(&adapter->adv_rss_lock);
1931 }
1932 break;
1933 default:
1934 if (adapter->current_op && (v_opcode != adapter->current_op))
1935 dev_warn(&adapter->pdev->dev, "Expected response %d from PF, received %d\n",
1936 adapter->current_op, v_opcode);
1937 break;
1938 } /* switch v_opcode */
1939 adapter->current_op = VIRTCHNL_OP_UNKNOWN;
1940 }
1941