FD.io VPP  v21.01.1
Vector Packet Processing
device.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2018 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17 
18 #include <vlib/vlib.h>
19 #include <vppinfra/ring.h>
20 #include <vlib/unix/unix.h>
21 #include <vlib/pci/pci.h>
22 #include <vnet/ethernet/ethernet.h>
23 
24 #include <avf/avf.h>
25 
26 #define AVF_MBOX_LEN 64
27 #define AVF_MBOX_BUF_SZ 512
28 #define AVF_RXQ_SZ 512
29 #define AVF_TXQ_SZ 512
30 #define AVF_ITR_INT 250
31 
32 #define PCI_VENDOR_ID_INTEL 0x8086
33 #define PCI_DEVICE_ID_INTEL_AVF 0x1889
34 #define PCI_DEVICE_ID_INTEL_X710_VF 0x154c
35 #define PCI_DEVICE_ID_INTEL_X722_VF 0x37cd
36 
37 /* *INDENT-OFF* */
39  .class_name = "avf",
40 };
41 /* *INDENT-ON* */
42 
44 void avf_delete_if (vlib_main_t * vm, avf_device_t * ad, int with_barrier);
45 
46 static pci_device_id_t avf_pci_device_ids[] = {
48  {.vendor_id = PCI_VENDOR_ID_INTEL,.device_id = PCI_DEVICE_ID_INTEL_X710_VF},
49  {.vendor_id = PCI_VENDOR_ID_INTEL,.device_id = PCI_DEVICE_ID_INTEL_X722_VF},
50  {0},
51 };
52 
53 const static char *virtchnl_event_names[] = {
54 #define _(v, n) [v] = #n,
56 #undef _
57 };
58 
59 typedef enum
60 {
65 
66 static inline void
68 {
69  u32 dyn_ctl0 = 0, icr0_ena = 0;
70 
71  dyn_ctl0 |= (3 << 3); /* 11b = No ITR update */
72 
73  avf_reg_write (ad, AVFINT_ICR0_ENA1, icr0_ena);
74  avf_reg_write (ad, AVFINT_DYN_CTL0, dyn_ctl0);
75  avf_reg_flush (ad);
76 
77  if (state == AVF_IRQ_STATE_DISABLED)
78  return;
79 
80  dyn_ctl0 = 0;
81  icr0_ena = 0;
82 
83  icr0_ena |= (1 << 30); /* [30] Admin Queue Enable */
84 
85  dyn_ctl0 |= (1 << 0); /* [0] Interrupt Enable */
86  dyn_ctl0 |= (1 << 1); /* [1] Clear PBA */
87  dyn_ctl0 |= (2 << 3); /* [4:3] ITR Index, 11b = No ITR update */
88  dyn_ctl0 |= ((AVF_ITR_INT / 2) << 5); /* [16:5] ITR Interval in 2us steps */
89 
90  avf_reg_write (ad, AVFINT_ICR0_ENA1, icr0_ena);
91  avf_reg_write (ad, AVFINT_DYN_CTL0, dyn_ctl0);
92  avf_reg_flush (ad);
93 }
94 
95 static inline void
97 {
98  u32 dyn_ctln = 0;
99 
100  /* disable */
101  avf_reg_write (ad, AVFINT_DYN_CTLN (line), dyn_ctln);
102  avf_reg_flush (ad);
103 
104  if (state == AVF_IRQ_STATE_DISABLED)
105  return;
106 
107  dyn_ctln |= (1 << 1); /* [1] Clear PBA */
108  if (state == AVF_IRQ_STATE_WB_ON_ITR)
109  {
110  /* minimal ITR interval, use ITR1 */
111  dyn_ctln |= (1 << 3); /* [4:3] ITR Index */
112  dyn_ctln |= ((32 / 2) << 5); /* [16:5] ITR Interval in 2us steps */
113  dyn_ctln |= (1 << 30); /* [30] Writeback on ITR */
114  }
115  else
116  {
117  /* configured ITR interval, use ITR0 */
118  dyn_ctln |= (1 << 0); /* [0] Interrupt Enable */
119  dyn_ctln |= ((AVF_ITR_INT / 2) << 5); /* [16:5] ITR Interval in 2us steps */
120  }
121 
122  avf_reg_write (ad, AVFINT_DYN_CTLN (line), dyn_ctln);
123  avf_reg_flush (ad);
124 }
125 
126 
127 clib_error_t *
129  void *data, int len)
130 {
131  clib_error_t *err = 0;
132  avf_aq_desc_t *d, dc;
133  f64 t0, suspend_time = AVF_AQ_ENQ_SUSPEND_TIME;
134 
135  d = &ad->atq[ad->atq_next_slot];
136  clib_memcpy_fast (d, dt, sizeof (avf_aq_desc_t));
137  d->flags |= AVF_AQ_F_RD | AVF_AQ_F_SI;
138  if (len)
139  d->datalen = len;
140  if (len)
141  {
142  u64 pa;
143  pa = ad->atq_bufs_pa + ad->atq_next_slot * AVF_MBOX_BUF_SZ;
144  d->addr_hi = (u32) (pa >> 32);
145  d->addr_lo = (u32) pa;
147  data, len);
148  d->flags |= AVF_AQ_F_BUF;
149  }
150 
151  if (ad->flags & AVF_DEVICE_F_ELOG)
152  clib_memcpy_fast (&dc, d, sizeof (avf_aq_desc_t));
153 
155  ad->atq_next_slot = (ad->atq_next_slot + 1) % AVF_MBOX_LEN;
157  avf_reg_flush (ad);
158 
159  t0 = vlib_time_now (vm);
160 retry:
161  vlib_process_suspend (vm, suspend_time);
162 
163  if (((d->flags & AVF_AQ_F_DD) == 0) || ((d->flags & AVF_AQ_F_CMP) == 0))
164  {
165  f64 t = vlib_time_now (vm) - t0;
166  if (t > AVF_AQ_ENQ_MAX_WAIT_TIME)
167  {
168  avf_log_err (ad, "aq_desc_enq failed (timeout %.3fs)", t);
169  err = clib_error_return (0, "adminq enqueue timeout [opcode 0x%x]",
170  d->opcode);
171  goto done;
172  }
173  suspend_time *= 2;
174  goto retry;
175  }
176 
177  clib_memcpy_fast (dt, d, sizeof (avf_aq_desc_t));
178  if (d->flags & AVF_AQ_F_ERR)
179  return clib_error_return (0, "adminq enqueue error [opcode 0x%x, retval "
180  "%d]", d->opcode, d->retval);
181 
182 done:
183  if (ad->flags & AVF_DEVICE_F_ELOG)
184  {
185  /* *INDENT-OFF* */
186  ELOG_TYPE_DECLARE (el) =
187  {
188  .format = "avf[%d] aq enq: s_flags 0x%x r_flags 0x%x opcode 0x%x "
189  "datalen %d retval %d",
190  .format_args = "i4i2i2i2i2i2",
191  };
192  struct
193  {
194  u32 dev_instance;
195  u16 s_flags;
196  u16 r_flags;
197  u16 opcode;
198  u16 datalen;
199  u16 retval;
200  } *ed;
201  ed = ELOG_DATA (&vm->elog_main, el);
202  ed->dev_instance = ad->dev_instance;
203  ed->s_flags = dc.flags;
204  ed->r_flags = d->flags;
205  ed->opcode = dc.opcode;
206  ed->datalen = dc.datalen;
207  ed->retval = d->retval;
208  /* *INDENT-ON* */
209  }
210 
211  return err;
212 }
213 
214 clib_error_t *
216  u32 val)
217 {
218  clib_error_t *err;
219  avf_aq_desc_t d = {.opcode = 0x207,.param1 = reg,.param3 = val };
220  err = avf_aq_desc_enq (vm, ad, &d, 0, 0);
221 
222  if (ad->flags & AVF_DEVICE_F_ELOG)
223  {
224  /* *INDENT-OFF* */
225  ELOG_TYPE_DECLARE (el) =
226  {
227  .format = "avf[%d] rx ctl reg write: reg 0x%x val 0x%x ",
228  .format_args = "i4i4i4",
229  };
230  struct
231  {
232  u32 dev_instance;
233  u32 reg;
234  u32 val;
235  } *ed;
236  ed = ELOG_DATA (&vm->elog_main, el);
237  ed->dev_instance = ad->dev_instance;
238  ed->reg = reg;
239  ed->val = val;
240  /* *INDENT-ON* */
241  }
242  return err;
243 }
244 
245 clib_error_t *
246 avf_rxq_init (vlib_main_t * vm, avf_device_t * ad, u16 qid, u16 rxq_size)
247 {
248  clib_error_t *err;
249  avf_rxq_t *rxq;
250  u32 n_alloc, i;
251 
253  rxq = vec_elt_at_index (ad->rxqs, qid);
254  rxq->size = rxq_size;
255  rxq->next = 0;
257  sizeof (avf_rx_desc_t),
259  ad->numa_node);
260 
261  rxq->buffer_pool_index =
263 
264  if (rxq->descs == 0)
265  return vlib_physmem_last_error (vm);
266 
267  if ((err = vlib_pci_map_dma (vm, ad->pci_dev_handle, (void *) rxq->descs)))
268  return err;
269 
270  clib_memset ((void *) rxq->descs, 0, rxq->size * sizeof (avf_rx_desc_t));
272  rxq->qrx_tail = ad->bar0 + AVF_QRX_TAIL (qid);
273 
274  n_alloc = vlib_buffer_alloc_from_pool (vm, rxq->bufs, rxq->size - 8,
275  rxq->buffer_pool_index);
276 
277  if (n_alloc == 0)
278  return clib_error_return (0, "buffer allocation error");
279 
280  rxq->n_enqueued = n_alloc;
281  avf_rx_desc_t *d = rxq->descs;
282  for (i = 0; i < n_alloc; i++)
283  {
284  vlib_buffer_t *b = vlib_get_buffer (vm, rxq->bufs[i]);
285  if (ad->flags & AVF_DEVICE_F_VA_DMA)
286  d->qword[0] = vlib_buffer_get_va (b);
287  else
288  d->qword[0] = vlib_buffer_get_pa (vm, b);
289  d++;
290  }
291 
292  ad->n_rx_queues = clib_min (ad->num_queue_pairs, qid + 1);
293  return 0;
294 }
295 
296 clib_error_t *
297 avf_txq_init (vlib_main_t * vm, avf_device_t * ad, u16 qid, u16 txq_size)
298 {
299  clib_error_t *err;
300  avf_txq_t *txq;
302  ad->numa_node);
303 
304  if (qid >= ad->num_queue_pairs)
305  {
306  qid = qid % ad->num_queue_pairs;
307  txq = vec_elt_at_index (ad->txqs, qid);
308  if (txq->lock == 0)
309  clib_spinlock_init (&txq->lock);
310  ad->flags |= AVF_DEVICE_F_SHARED_TXQ_LOCK;
311  return 0;
312  }
313 
315  txq = vec_elt_at_index (ad->txqs, qid);
316  txq->size = txq_size;
317  txq->next = 0;
318 
319  /* Prepare a placeholder buffer to maintain a 1-1
320  relationship between bufs and descs when a context
321  descriptor is added in descs */
323  (vm, &txq->ctx_desc_placeholder_bi, 1, bpi))
324  return clib_error_return (0, "buffer allocation error");
325 
327  sizeof (avf_tx_desc_t),
329  ad->numa_node);
330  if (txq->descs == 0)
331  return vlib_physmem_last_error (vm);
332 
333  if ((err = vlib_pci_map_dma (vm, ad->pci_dev_handle, (void *) txq->descs)))
334  return err;
335 
337  txq->qtx_tail = ad->bar0 + AVF_QTX_TAIL (qid);
338 
339  /* initialize ring of pending RS slots */
341 
342  ad->n_tx_queues = clib_min (ad->num_queue_pairs, qid + 1);
343  return 0;
344 }
345 
346 typedef struct
347 {
351 
352 void
354 {
355  avf_aq_desc_t *d;
356  u64 pa = ad->arq_bufs_pa + slot * AVF_MBOX_BUF_SZ;
357  d = &ad->arq[slot];
358  clib_memset (d, 0, sizeof (avf_aq_desc_t));
359  d->flags = AVF_AQ_F_BUF;
361  d->addr_hi = (u32) (pa >> 32);
362  d->addr_lo = (u32) pa;
363 }
364 
365 static inline uword
367 {
368  return (ad->flags & AVF_DEVICE_F_VA_DMA) ?
370 }
371 
372 static void
374 {
375  u64 pa;
376  int i;
377 
378  /* VF MailBox Transmit */
379  clib_memset (ad->atq, 0, sizeof (avf_aq_desc_t) * AVF_MBOX_LEN);
380  ad->atq_bufs_pa = avf_dma_addr (vm, ad, ad->atq_bufs);
381 
382  pa = avf_dma_addr (vm, ad, ad->atq);
383  avf_reg_write (ad, AVF_ATQT, 0); /* Tail */
384  avf_reg_write (ad, AVF_ATQH, 0); /* Head */
385  avf_reg_write (ad, AVF_ATQLEN, AVF_MBOX_LEN | (1ULL << 31)); /* len & ena */
386  avf_reg_write (ad, AVF_ATQBAL, (u32) pa); /* Base Address Low */
387  avf_reg_write (ad, AVF_ATQBAH, (u32) (pa >> 32)); /* Base Address High */
388 
389  /* VF MailBox Receive */
390  clib_memset (ad->arq, 0, sizeof (avf_aq_desc_t) * AVF_MBOX_LEN);
391  ad->arq_bufs_pa = avf_dma_addr (vm, ad, ad->arq_bufs);
392 
393  for (i = 0; i < AVF_MBOX_LEN; i++)
394  avf_arq_slot_init (ad, i);
395 
396  pa = avf_dma_addr (vm, ad, ad->arq);
397 
398  avf_reg_write (ad, AVF_ARQH, 0); /* Head */
399  avf_reg_write (ad, AVF_ARQT, 0); /* Head */
400  avf_reg_write (ad, AVF_ARQLEN, AVF_MBOX_LEN | (1ULL << 31)); /* len & ena */
401  avf_reg_write (ad, AVF_ARQBAL, (u32) pa); /* Base Address Low */
402  avf_reg_write (ad, AVF_ARQBAH, (u32) (pa >> 32)); /* Base Address High */
403  avf_reg_write (ad, AVF_ARQT, AVF_MBOX_LEN - 1); /* Tail */
404 
405  ad->atq_next_slot = 0;
406  ad->arq_next_slot = 0;
407 }
408 
409 clib_error_t *
411  void *in, int in_len, void *out, int out_len)
412 {
413  clib_error_t *err;
414  avf_aq_desc_t *d, dt = {.opcode = 0x801,.v_opcode = op };
415  u32 head;
416  f64 t0, suspend_time = AVF_SEND_TO_PF_SUSPEND_TIME;
417 
418  /* adminq operations should be only done from process node after device
419  * is initialized */
420  ASSERT ((ad->flags & AVF_DEVICE_F_INITIALIZED) == 0 ||
422 
423  /* suppress interrupt in the next adminq receive slot
424  as we are going to wait for response
425  we only need interrupts when event is received */
426  d = &ad->arq[ad->arq_next_slot];
427  d->flags |= AVF_AQ_F_SI;
428 
429  if ((err = avf_aq_desc_enq (vm, ad, &dt, in, in_len)))
430  return err;
431 
432  t0 = vlib_time_now (vm);
433 retry:
434  head = avf_get_u32 (ad->bar0, AVF_ARQH);
435 
436  if (ad->arq_next_slot == head)
437  {
438  f64 t = vlib_time_now (vm) - t0;
440  {
441  avf_log_err (ad, "send_to_pf failed (timeout %.3fs)", t);
442  return clib_error_return (0, "timeout");
443  }
444  vlib_process_suspend (vm, suspend_time);
445  suspend_time *= 2;
446  goto retry;
447  }
448 
449  d = &ad->arq[ad->arq_next_slot];
450 
451  if (d->v_opcode == VIRTCHNL_OP_EVENT)
452  {
453  void *buf = ad->arq_bufs + ad->arq_next_slot * AVF_MBOX_BUF_SZ;
455 
456  if ((d->datalen != sizeof (virtchnl_pf_event_t)) ||
457  ((d->flags & AVF_AQ_F_BUF) == 0))
458  return clib_error_return (0, "event message error");
459 
460  vec_add2 (ad->events, e, 1);
461  clib_memcpy_fast (e, buf, sizeof (virtchnl_pf_event_t));
463  ad->arq_next_slot++;
464  /* reset timer */
465  t0 = vlib_time_now (vm);
466  suspend_time = AVF_SEND_TO_PF_SUSPEND_TIME;
467  goto retry;
468  }
469 
470  if (d->v_opcode != op)
471  {
472  err =
474  "unexpected message receiver [v_opcode = %u, "
475  "expected %u, v_retval %d]", d->v_opcode, op,
476  d->v_retval);
477  goto done;
478  }
479 
480  if (d->v_retval)
481  {
482  err = clib_error_return (0, "error [v_opcode = %u, v_retval %d]",
483  d->v_opcode, d->v_retval);
484  goto done;
485  }
486 
487  if (d->flags & AVF_AQ_F_BUF)
488  {
489  void *buf = ad->arq_bufs + ad->arq_next_slot * AVF_MBOX_BUF_SZ;
490  clib_memcpy_fast (out, buf, out_len);
491  }
492 
495  avf_reg_flush (ad);
496  ad->arq_next_slot = (ad->arq_next_slot + 1) % AVF_MBOX_LEN;
497 
498 done:
499 
500  if (ad->flags & AVF_DEVICE_F_ELOG)
501  {
502  /* *INDENT-OFF* */
503  ELOG_TYPE_DECLARE (el) =
504  {
505  .format = "avf[%d] send to pf: v_opcode %s (%d) v_retval 0x%x",
506  .format_args = "i4t4i4i4",
507  .n_enum_strings = VIRTCHNL_N_OPS,
508  .enum_strings = {
509 #define _(v, n) [v] = #n,
511 #undef _
512  },
513  };
514  struct
515  {
516  u32 dev_instance;
517  u32 v_opcode;
518  u32 v_opcode_val;
519  u32 v_retval;
520  } *ed;
521  ed = ELOG_DATA (&vm->elog_main, el);
522  ed->dev_instance = ad->dev_instance;
523  ed->v_opcode = op;
524  ed->v_opcode_val = op;
525  ed->v_retval = d->v_retval;
526  /* *INDENT-ON* */
527  }
528  return err;
529 }
530 
531 clib_error_t *
534 {
535  clib_error_t *err = 0;
536  virtchnl_version_info_t myver = {
538  .minor = VIRTCHNL_VERSION_MINOR,
539  };
540 
541  avf_log_debug (ad, "version: major %u minor %u", myver.major, myver.minor);
542 
543  err = avf_send_to_pf (vm, ad, VIRTCHNL_OP_VERSION, &myver,
544  sizeof (virtchnl_version_info_t), ver,
545  sizeof (virtchnl_version_info_t));
546 
547  if (err)
548  return err;
549 
550  return err;
551 }
552 
553 clib_error_t *
556 {
557  clib_error_t *err = 0;
558  u32 bitmap = (VIRTCHNL_VF_OFFLOAD_L2 | VIRTCHNL_VF_OFFLOAD_RSS_PF |
559  VIRTCHNL_VF_OFFLOAD_WB_ON_ITR | VIRTCHNL_VF_OFFLOAD_VLAN |
560  VIRTCHNL_VF_OFFLOAD_RX_POLLING |
561  VIRTCHNL_VF_CAP_ADV_LINK_SPEED);
562 
563  avf_log_debug (ad, "get_vf_reqources: bitmap 0x%x", bitmap);
564  err = avf_send_to_pf (vm, ad, VIRTCHNL_OP_GET_VF_RESOURCES, &bitmap,
565  sizeof (u32), res, sizeof (virtchnl_vf_resource_t));
566 
567  if (err == 0)
568  {
569  int i;
570  avf_log_debug (ad, "get_vf_reqources: num_vsis %u num_queue_pairs %u "
571  "max_vectors %u max_mtu %u vf_offload_flags 0x%04x "
572  "rss_key_size %u rss_lut_size %u",
573  res->num_vsis, res->num_queue_pairs, res->max_vectors,
574  res->max_mtu, res->vf_offload_flags, res->rss_key_size,
575  res->rss_lut_size);
576  for (i = 0; i < res->num_vsis; i++)
577  avf_log_debug (ad, "get_vf_reqources_vsi[%u]: vsi_id %u "
578  "num_queue_pairs %u vsi_type %u qset_handle %u "
579  "default_mac_addr %U", i,
580  res->vsi_res[i].vsi_id,
581  res->vsi_res[i].num_queue_pairs,
582  res->vsi_res[i].vsi_type,
583  res->vsi_res[i].qset_handle,
585  res->vsi_res[i].default_mac_addr);
586  }
587 
588  return err;
589 }
590 
591 clib_error_t *
593 {
594  int msg_len = sizeof (virtchnl_rss_lut_t) + ad->rss_lut_size - 1;
595  int i;
596  u8 msg[msg_len];
597  virtchnl_rss_lut_t *rl;
598 
599  clib_memset (msg, 0, msg_len);
600  rl = (virtchnl_rss_lut_t *) msg;
601  rl->vsi_id = ad->vsi_id;
602  rl->lut_entries = ad->rss_lut_size;
603  for (i = 0; i < ad->rss_lut_size; i++)
604  rl->lut[i] = i % ad->n_rx_queues;
605 
606  avf_log_debug (ad, "config_rss_lut: vsi_id %u rss_lut_size %u lut 0x%U",
607  rl->vsi_id, rl->lut_entries, format_hex_bytes_no_wrap,
608  rl->lut, rl->lut_entries);
609 
610  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_CONFIG_RSS_LUT, msg, msg_len, 0,
611  0);
612 }
613 
614 clib_error_t *
616 {
617  int msg_len = sizeof (virtchnl_rss_key_t) + ad->rss_key_size - 1;
618  int i;
619  u8 msg[msg_len];
620  virtchnl_rss_key_t *rk;
621 
622  clib_memset (msg, 0, msg_len);
623  rk = (virtchnl_rss_key_t *) msg;
624  rk->vsi_id = ad->vsi_id;
625  rk->key_len = ad->rss_key_size;
626  u32 seed = random_default_seed ();
627  for (i = 0; i < ad->rss_key_size; i++)
628  rk->key[i] = (u8) random_u32 (&seed);
629 
630  avf_log_debug (ad, "config_rss_key: vsi_id %u rss_key_size %u key 0x%U",
631  rk->vsi_id, rk->key_len, format_hex_bytes_no_wrap, rk->key,
632  rk->key_len);
633 
634  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_CONFIG_RSS_KEY, msg, msg_len, 0,
635  0);
636 }
637 
638 clib_error_t *
640 {
641  avf_log_debug (ad, "disable_vlan_stripping");
642 
643  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING, 0, 0, 0,
644  0);
645 }
646 
647 clib_error_t *
649  int is_enable)
650 {
651  virtchnl_promisc_info_t pi = { 0 };
652 
653  pi.vsi_id = ad->vsi_id;
654 
655  if (is_enable)
656  pi.flags = FLAG_VF_UNICAST_PROMISC | FLAG_VF_MULTICAST_PROMISC;
657 
658  avf_log_debug (ad, "config_promisc_mode: unicast %s multicast %s",
659  pi.flags & FLAG_VF_UNICAST_PROMISC ? "on" : "off",
660  pi.flags & FLAG_VF_MULTICAST_PROMISC ? "on" : "off");
661 
662  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, &pi,
663  sizeof (virtchnl_promisc_info_t), 0, 0);
664 }
665 
666 
667 clib_error_t *
669 {
670  int i;
671  int n_qp = clib_max (vec_len (ad->rxqs), vec_len (ad->txqs));
672  int msg_len = sizeof (virtchnl_vsi_queue_config_info_t) + n_qp *
674  u8 msg[msg_len];
676 
677  clib_memset (msg, 0, msg_len);
679  ci->vsi_id = ad->vsi_id;
680  ci->num_queue_pairs = n_qp;
681 
682  avf_log_debug (ad, "config_vsi_queues: vsi_id %u num_queue_pairs %u",
683  ad->vsi_id, ci->num_queue_pairs);
684 
685  for (i = 0; i < n_qp; i++)
686  {
687  virtchnl_txq_info_t *txq = &ci->qpair[i].txq;
688  virtchnl_rxq_info_t *rxq = &ci->qpair[i].rxq;
689 
690  rxq->vsi_id = ad->vsi_id;
691  rxq->queue_id = i;
693  if (i < vec_len (ad->rxqs))
694  {
695  avf_rxq_t *q = vec_elt_at_index (ad->rxqs, i);
696  rxq->ring_len = q->size;
698  rxq->dma_ring_addr = avf_dma_addr (vm, ad, (void *) q->descs);
699  avf_reg_write (ad, AVF_QRX_TAIL (i), q->size - 1);
700  }
701  avf_log_debug (ad, "config_vsi_queues_rx[%u]: max_pkt_size %u "
702  "ring_len %u databuffer_size %u dma_ring_addr 0x%llx",
703  i, rxq->max_pkt_size, rxq->ring_len,
704  rxq->databuffer_size, rxq->dma_ring_addr);
705 
706  txq->vsi_id = ad->vsi_id;
707  txq->queue_id = i;
708  if (i < vec_len (ad->txqs))
709  {
710  avf_txq_t *q = vec_elt_at_index (ad->txqs, i);
711  txq->ring_len = q->size;
712  txq->dma_ring_addr = avf_dma_addr (vm, ad, (void *) q->descs);
713  }
714  avf_log_debug (ad, "config_vsi_queues_tx[%u]: ring_len %u "
715  "dma_ring_addr 0x%llx", i, txq->ring_len,
716  txq->dma_ring_addr);
717  }
718 
719  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_CONFIG_VSI_QUEUES, msg, msg_len,
720  0, 0);
721 }
722 
723 clib_error_t *
725 {
726  int msg_len = sizeof (virtchnl_irq_map_info_t) +
727  (ad->n_rx_irqs) * sizeof (virtchnl_vector_map_t);
728  u8 msg[msg_len];
730 
731  clib_memset (msg, 0, msg_len);
732  imi = (virtchnl_irq_map_info_t *) msg;
733  imi->num_vectors = ad->n_rx_irqs;
734 
735  for (int i = 0; i < ad->n_rx_irqs; i++)
736  {
737  imi->vecmap[i].vector_id = i + 1;
738  imi->vecmap[i].vsi_id = ad->vsi_id;
739  if (ad->n_rx_irqs == ad->n_rx_queues)
740  imi->vecmap[i].rxq_map = 1 << i;
741  else
742  imi->vecmap[i].rxq_map = pow2_mask (ad->n_rx_queues);;
743 
744  avf_log_debug (ad, "config_irq_map[%u/%u]: vsi_id %u vector_id %u "
745  "rxq_map %u", i, ad->n_rx_irqs - 1, ad->vsi_id,
746  imi->vecmap[i].vector_id, imi->vecmap[i].rxq_map);
747  }
748 
749 
750  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_CONFIG_IRQ_MAP, msg, msg_len, 0,
751  0);
752 }
753 
754 clib_error_t *
756  u8 * macs, int is_add)
757 {
758  int msg_len =
759  sizeof (virtchnl_ether_addr_list_t) +
760  count * sizeof (virtchnl_ether_addr_t);
761  u8 msg[msg_len];
763  int i;
764 
765  clib_memset (msg, 0, msg_len);
766  al = (virtchnl_ether_addr_list_t *) msg;
767  al->vsi_id = ad->vsi_id;
768  al->num_elements = count;
769 
770  avf_log_debug (ad, "add_del_eth_addr: vsi_id %u num_elements %u is_add %u",
771  ad->vsi_id, al->num_elements, is_add);
772 
773  for (i = 0; i < count; i++)
774  {
775  clib_memcpy_fast (&al->list[i].addr, macs + i * 6, 6);
776  avf_log_debug (ad, "add_del_eth_addr[%u]: %U", i,
778  }
779  return avf_send_to_pf (vm, ad, is_add ? VIRTCHNL_OP_ADD_ETH_ADDR :
780  VIRTCHNL_OP_DEL_ETH_ADDR, msg, msg_len, 0, 0);
781 }
782 
783 clib_error_t *
785 {
786  virtchnl_queue_select_t qs = { 0 };
787  int i = 0;
788  qs.vsi_id = ad->vsi_id;
789  qs.rx_queues = rx;
790  qs.tx_queues = tx;
791 
792  avf_log_debug (ad, "enable_queues: vsi_id %u rx_queues %u tx_queues %u",
793  ad->vsi_id, qs.rx_queues, qs.tx_queues);
794 
795  while (rx)
796  {
797  if (rx & (1 << i))
798  {
799  avf_rxq_t *rxq = vec_elt_at_index (ad->rxqs, i);
800  avf_reg_write (ad, AVF_QRX_TAIL (i), rxq->n_enqueued);
801  rx &= ~(1 << i);
802  }
803  i++;
804  }
805  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_ENABLE_QUEUES, &qs,
806  sizeof (virtchnl_queue_select_t), 0, 0);
807 }
808 
809 clib_error_t *
812 {
813  virtchnl_queue_select_t qs = { 0 };
814  qs.vsi_id = ad->vsi_id;
815 
816  avf_log_debug (ad, "get_stats: vsi_id %u", ad->vsi_id);
817 
818  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_GET_STATS,
819  &qs, sizeof (virtchnl_queue_select_t),
820  es, sizeof (virtchnl_eth_stats_t));
821 }
822 
823 clib_error_t *
825 {
826  avf_aq_desc_t d = { 0 };
828  u32 rstat;
829  f64 t0, t = 0, suspend_time = AVF_RESET_SUSPEND_TIME;
830 
831  avf_log_debug (ad, "reset");
832 
833  d.opcode = 0x801;
834  d.v_opcode = VIRTCHNL_OP_RESET_VF;
835  if ((error = avf_aq_desc_enq (vm, ad, &d, 0, 0)))
836  return error;
837 
838  t0 = vlib_time_now (vm);
839 retry:
840  vlib_process_suspend (vm, suspend_time);
841 
842  rstat = avf_get_u32 (ad->bar0, AVFGEN_RSTAT);
843 
844  if (rstat == 2 || rstat == 3)
845  {
846  avf_log_debug (ad, "reset completed in %.3fs", t);
847  return 0;
848  }
849 
850  t = vlib_time_now (vm) - t0;
851  if (t > AVF_RESET_MAX_WAIT_TIME)
852  {
853  avf_log_err (ad, "reset failed (timeout %.3fs)", t);
854  return clib_error_return (0, "reset failed (timeout)");
855  }
856 
857  suspend_time *= 2;
858  goto retry;
859 }
860 
861 clib_error_t *
863 {
864  virtchnl_vf_res_request_t res_req = { 0 };
866  u32 rstat;
867  f64 t0, t, suspend_time = AVF_RESET_SUSPEND_TIME;
868 
869  res_req.num_queue_pairs = num_queue_pairs;
870 
871  avf_log_debug (ad, "request_queues: num_queue_pairs %u", num_queue_pairs);
872 
873  error = avf_send_to_pf (vm, ad, VIRTCHNL_OP_REQUEST_QUEUES, &res_req,
874  sizeof (virtchnl_vf_res_request_t), &res_req,
875  sizeof (virtchnl_vf_res_request_t));
876 
877  /*
878  * if PF responds, the request failed
879  * else PF initializes restart and avf_send_to_pf returns an error
880  */
881  if (!error)
882  {
883  return clib_error_return (0, "requested more than %u queue pairs",
884  res_req.num_queue_pairs);
885  }
886 
887  t0 = vlib_time_now (vm);
888 retry:
889  vlib_process_suspend (vm, suspend_time);
890  t = vlib_time_now (vm) - t0;
891 
892  rstat = avf_get_u32 (ad->bar0, AVFGEN_RSTAT);
893 
894  if ((rstat == VIRTCHNL_VFR_COMPLETED) || (rstat == VIRTCHNL_VFR_VFACTIVE))
895  goto done;
896 
897  if (t > AVF_RESET_MAX_WAIT_TIME)
898  {
899  avf_log_err (ad, "request queues failed (timeout %.3f seconds)", t);
900  return clib_error_return (0, "request queues failed (timeout)");
901  }
902 
903  suspend_time *= 2;
904  goto retry;
905 
906 done:
907  return NULL;
908 }
909 
910 clib_error_t *
912  avf_create_if_args_t * args)
913 {
914  virtchnl_version_info_t ver = { 0 };
915  virtchnl_vf_resource_t res = { 0 };
918  int i, wb_on_itr;
919 
920  avf_adminq_init (vm, ad);
921 
922  if ((error = avf_request_queues (vm, ad, clib_max (tm->n_vlib_mains,
923  args->rxq_num))))
924  {
925  /* we failed to get more queues, but still we want to proceed */
926  clib_error_free (error);
927 
928  if ((error = avf_device_reset (vm, ad)))
929  return error;
930  }
931 
932  avf_adminq_init (vm, ad);
933 
934  /*
935  * OP_VERSION
936  */
937  if ((error = avf_op_version (vm, ad, &ver)))
938  return error;
939 
940  if (ver.major != VIRTCHNL_VERSION_MAJOR ||
942  return clib_error_return (0, "incompatible protocol version "
943  "(remote %d.%d)", ver.major, ver.minor);
944 
945  /*
946  * OP_GET_VF_RESOURCES
947  */
948  if ((error = avf_op_get_vf_resources (vm, ad, &res)))
949  return error;
950 
951  if (res.num_vsis != 1 || res.vsi_res[0].vsi_type != VIRTCHNL_VSI_SRIOV)
952  return clib_error_return (0, "unexpected GET_VF_RESOURCE reply received");
953 
954  ad->vsi_id = res.vsi_res[0].vsi_id;
957  ad->max_vectors = res.max_vectors;
958  ad->max_mtu = res.max_mtu;
959  ad->rss_key_size = res.rss_key_size;
960  ad->rss_lut_size = res.rss_lut_size;
961  wb_on_itr = (ad->feature_bitmap & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR) != 0;
962 
964 
965  /*
966  * Disable VLAN stripping
967  */
968  if ((error = avf_op_disable_vlan_stripping (vm, ad)))
969  return error;
970 
971  /*
972  * Init Queues
973  */
974  if (args->rxq_num == 0)
975  {
976  args->rxq_num = 1;
977  }
978  else if (args->rxq_num > ad->num_queue_pairs)
979  {
980  args->rxq_num = ad->num_queue_pairs;
981  avf_log_warn (ad, "Requested more rx queues than queue pairs available."
982  "Using %u rx queues.", args->rxq_num);
983  }
984 
985  for (i = 0; i < args->rxq_num; i++)
986  if ((error = avf_rxq_init (vm, ad, i, args->rxq_size)))
987  return error;
988 
989  for (i = 0; i < tm->n_vlib_mains; i++)
990  if ((error = avf_txq_init (vm, ad, i, args->txq_size)))
991  return error;
992 
993  if (ad->max_vectors > ad->n_rx_queues)
994  {
995  ad->flags |= AVF_DEVICE_F_RX_INT;
996  ad->n_rx_irqs = args->rxq_num;
997  }
998  else
999  ad->n_rx_irqs = 1;
1000 
1001 
1002  if ((ad->feature_bitmap & VIRTCHNL_VF_OFFLOAD_RSS_PF) &&
1003  (error = avf_op_config_rss_lut (vm, ad)))
1004  return error;
1005 
1006  if ((ad->feature_bitmap & VIRTCHNL_VF_OFFLOAD_RSS_PF) &&
1007  (error = avf_op_config_rss_key (vm, ad)))
1008  return error;
1009 
1010  if ((error = avf_op_config_vsi_queues (vm, ad)))
1011  return error;
1012 
1013  if ((error = avf_op_config_irq_map (vm, ad)))
1014  return error;
1015 
1017 
1018  for (i = 0; i < ad->n_rx_irqs; i++)
1019  avf_irq_n_set_state (ad, i, wb_on_itr ? AVF_IRQ_STATE_WB_ON_ITR :
1021 
1022  if ((error = avf_op_add_del_eth_addr (vm, ad, 1, ad->hwaddr, 1 /* add */ )))
1023  return error;
1024 
1025  if ((error = avf_op_enable_queues (vm, ad, pow2_mask (ad->n_rx_queues),
1026  pow2_mask (ad->n_tx_queues))))
1027  return error;
1028 
1029  ad->flags |= AVF_DEVICE_F_INITIALIZED;
1030  return error;
1031 }
1032 
1033 void
1035 {
1036  vnet_main_t *vnm = vnet_get_main ();
1038  u32 r;
1039 
1040  if (ad->flags & AVF_DEVICE_F_ERROR)
1041  return;
1042 
1043  if ((ad->flags & AVF_DEVICE_F_INITIALIZED) == 0)
1044  return;
1045 
1046  ASSERT (ad->error == 0);
1047 
1048  /* do not process device in reset state */
1049  r = avf_get_u32 (ad->bar0, AVFGEN_RSTAT);
1050  if (r != VIRTCHNL_VFR_VFACTIVE)
1051  return;
1052 
1053  r = avf_get_u32 (ad->bar0, AVF_ARQLEN);
1054  if ((r & 0xf0000000) != (1ULL << 31))
1055  {
1056  ad->error = clib_error_return (0, "arq not enabled, arqlen = 0x%x", r);
1057  avf_log_err (ad, "error: %U", format_clib_error, ad->error);
1058  goto error;
1059  }
1060 
1061  r = avf_get_u32 (ad->bar0, AVF_ATQLEN);
1062  if ((r & 0xf0000000) != (1ULL << 31))
1063  {
1064  ad->error = clib_error_return (0, "atq not enabled, atqlen = 0x%x", r);
1065  avf_log_err (ad, "error: %U", format_clib_error, ad->error);
1066  goto error;
1067  }
1068 
1069  if (is_irq == 0)
1070  avf_op_get_stats (vm, ad, &ad->eth_stats);
1071 
1072  /* *INDENT-OFF* */
1073  vec_foreach (e, ad->events)
1074  {
1075  avf_log_debug (ad, "event: %s (%u) sev %d",
1077  if (e->event == VIRTCHNL_EVENT_LINK_CHANGE)
1078  {
1079  int link_up;
1080  virtchnl_link_speed_t speed = e->event_data.link_event.link_speed;
1081  u32 flags = 0;
1082  u32 mbps = 0;
1083 
1084  if (ad->feature_bitmap & VIRTCHNL_VF_CAP_ADV_LINK_SPEED)
1085  link_up = e->event_data.link_event_adv.link_status;
1086  else
1087  link_up = e->event_data.link_event.link_status;
1088 
1089  if (ad->feature_bitmap & VIRTCHNL_VF_CAP_ADV_LINK_SPEED)
1090  mbps = e->event_data.link_event_adv.link_speed;
1091  if (speed == VIRTCHNL_LINK_SPEED_40GB)
1092  mbps = 40000;
1093  else if (speed == VIRTCHNL_LINK_SPEED_25GB)
1094  mbps = 25000;
1095  else if (speed == VIRTCHNL_LINK_SPEED_10GB)
1096  mbps = 10000;
1097  else if (speed == VIRTCHNL_LINK_SPEED_5GB)
1098  mbps = 5000;
1099  else if (speed == VIRTCHNL_LINK_SPEED_2_5GB)
1100  mbps = 2500;
1101  else if (speed == VIRTCHNL_LINK_SPEED_1GB)
1102  mbps = 1000;
1103  else if (speed == VIRTCHNL_LINK_SPEED_100MB)
1104  mbps = 100;
1105 
1106  avf_log_debug (ad, "event_link_change: status %d speed %u mbps",
1107  link_up, mbps);
1108 
1109  if (link_up && (ad->flags & AVF_DEVICE_F_LINK_UP) == 0)
1110  {
1111  ad->flags |= AVF_DEVICE_F_LINK_UP;
1114  vnet_hw_interface_set_flags (vnm, ad->hw_if_index, flags);
1116  mbps * 1000);
1117  ad->link_speed = mbps;
1118  }
1119  else if (!link_up && (ad->flags & AVF_DEVICE_F_LINK_UP) != 0)
1120  {
1121  ad->flags &= ~AVF_DEVICE_F_LINK_UP;
1122  ad->link_speed = 0;
1123  }
1124 
1125  if (ad->flags & AVF_DEVICE_F_ELOG)
1126  {
1127  ELOG_TYPE_DECLARE (el) =
1128  {
1129  .format = "avf[%d] link change: link_status %d "
1130  "link_speed %d mbps",
1131  .format_args = "i4i1i4",
1132  };
1133  struct
1134  {
1135  u32 dev_instance;
1136  u8 link_status;
1137  u32 link_speed;
1138  } *ed;
1139  ed = ELOG_DATA (&vm->elog_main, el);
1140  ed->dev_instance = ad->dev_instance;
1141  ed->link_status = link_up;
1142  ed->link_speed = mbps;
1143  }
1144  }
1145  else
1146  {
1147  if (ad->flags & AVF_DEVICE_F_ELOG)
1148  {
1149  ELOG_TYPE_DECLARE (el) =
1150  {
1151  .format = "avf[%d] unknown event: event %d severity %d",
1152  .format_args = "i4i4i1i1",
1153  };
1154  struct
1155  {
1156  u32 dev_instance;
1157  u32 event;
1158  u32 severity;
1159  } *ed;
1160  ed = ELOG_DATA (&vm->elog_main, el);
1161  ed->dev_instance = ad->dev_instance;
1162  ed->event = e->event;
1163  ed->severity = e->severity;
1164  }
1165  }
1166  }
1167  /* *INDENT-ON* */
1168  vec_reset_length (ad->events);
1169 
1170  return;
1171 
1172 error:
1173  ad->flags |= AVF_DEVICE_F_ERROR;
1174  ASSERT (ad->error != 0);
1176 }
1177 
1178 static void
1180 {
1182 
1184  req->error = avf_op_add_del_eth_addr (vm, ad, 1, req->eth_addr,
1185  req->is_add);
1186  else if (req->type == AVF_PROCESS_REQ_CONFIG_PROMISC_MDDE)
1187  req->error = avf_op_config_promisc_mode (vm, ad, req->is_enable);
1188  else
1189  clib_panic ("BUG: unknown avf proceess request type");
1190 
1191  if (req->calling_process_index != avf_process_node.index)
1193 }
1194 
1195 static clib_error_t *
1197 {
1198  uword *event_data = 0;
1200 
1201  if (req->calling_process_index != avf_process_node.index)
1202  {
1204  AVF_PROCESS_EVENT_REQ, req);
1205 
1207 
1208  if (vlib_process_get_events (vm, &event_data) != 0)
1209  clib_panic ("avf process node failed to reply in 5 seconds");
1210  vec_free (event_data);
1211  }
1212  else
1213  avf_process_handle_request (vm, req);
1214 
1215  return req->error;
1216 }
1217 
1218 static u32
1220 {
1221  avf_process_req_t req;
1224  clib_error_t *err;
1225 
1226  switch (flags)
1227  {
1229  ad->flags &= ~AVF_DEVICE_F_PROMISC;
1230  break;
1232  ad->flags |= AVF_DEVICE_F_PROMISC;
1233  break;
1234  default:
1235  return ~0;
1236  }
1237 
1238  req.is_enable = ((ad->flags & AVF_DEVICE_F_PROMISC) != 0);
1240  req.dev_instance = hw->dev_instance;
1241 
1242  if ((err = avf_process_request (vm, &req)))
1243  {
1244  avf_log_err (ad, "error: %U", format_clib_error, err);
1245  clib_error_free (err);
1246  return ~0;
1247  }
1248  return 0;
1249 }
1250 
1251 static uword
1253 {
1254  avf_main_t *am = &avf_main;
1255  uword *event_data = 0, event_type;
1256  int enabled = 0, irq;
1257  f64 last_run_duration = 0;
1258  f64 last_periodic_time = 0;
1259  avf_device_t **dev_pointers = 0;
1260  u32 i;
1261 
1262  while (1)
1263  {
1264  if (enabled)
1265  vlib_process_wait_for_event_or_clock (vm, 5.0 - last_run_duration);
1266  else
1268 
1269  event_type = vlib_process_get_events (vm, &event_data);
1270  irq = 0;
1271 
1272  switch (event_type)
1273  {
1274  case ~0:
1275  last_periodic_time = vlib_time_now (vm);
1276  break;
1278  enabled = 1;
1279  break;
1281  for (int i = 0; i < vec_len (event_data); i++)
1282  {
1283  avf_device_t *ad = avf_get_device (event_data[i]);
1284  avf_delete_if (vm, ad, /* with_barrier */ 1);
1285  }
1286  if (pool_elts (am->devices) < 1)
1287  enabled = 0;
1288  break;
1290  irq = 1;
1291  break;
1292  case AVF_PROCESS_EVENT_REQ:
1293  for (int i = 0; i < vec_len (event_data); i++)
1294  avf_process_handle_request (vm, (void *) event_data[i]);
1295  break;
1296 
1297  default:
1298  ASSERT (0);
1299  }
1300 
1301  vec_reset_length (event_data);
1302 
1303  if (enabled == 0)
1304  continue;
1305 
1306  /* create local list of device pointers as device pool may grow
1307  * during suspend */
1308  vec_reset_length (dev_pointers);
1309  /* *INDENT-OFF* */
1310  pool_foreach_index (i, am->devices)
1311  {
1312  vec_add1 (dev_pointers, avf_get_device (i));
1313  }
1314 
1315  vec_foreach_index (i, dev_pointers)
1316  {
1317  avf_process_one_device (vm, dev_pointers[i], irq);
1318  };
1319  /* *INDENT-ON* */
1320  last_run_duration = vlib_time_now (vm) - last_periodic_time;
1321  }
1322  return 0;
1323 }
1324 
1325 /* *INDENT-OFF* */
1327  .function = avf_process,
1328  .type = VLIB_NODE_TYPE_PROCESS,
1329  .name = "avf-process",
1330 };
1331 /* *INDENT-ON* */
1332 
1333 static void
1335 {
1336  uword pd = vlib_pci_get_private_data (vm, h);
1337  avf_device_t *ad = avf_get_device (pd);
1338  u32 icr0;
1339 
1340  icr0 = avf_reg_read (ad, AVFINT_ICR0);
1341 
1342  if (ad->flags & AVF_DEVICE_F_ELOG)
1343  {
1344  /* *INDENT-OFF* */
1345  ELOG_TYPE_DECLARE (el) =
1346  {
1347  .format = "avf[%d] irq 0: icr0 0x%x",
1348  .format_args = "i4i4",
1349  };
1350  /* *INDENT-ON* */
1351  struct
1352  {
1353  u32 dev_instance;
1354  u32 icr0;
1355  } *ed;
1356 
1357  ed = ELOG_DATA (&vm->elog_main, el);
1358  ed->dev_instance = ad->dev_instance;
1359  ed->icr0 = icr0;
1360  }
1361 
1363 
1364  /* bit 30 - Send/Receive Admin queue interrupt indication */
1365  if (icr0 & (1 << 30))
1368 }
1369 
1370 static void
1372 {
1373  vnet_main_t *vnm = vnet_get_main ();
1374  uword pd = vlib_pci_get_private_data (vm, h);
1375  avf_device_t *ad = avf_get_device (pd);
1376 
1377  if (ad->flags & AVF_DEVICE_F_ELOG)
1378  {
1379  /* *INDENT-OFF* */
1380  ELOG_TYPE_DECLARE (el) =
1381  {
1382  .format = "avf[%d] irq %d: received",
1383  .format_args = "i4i2",
1384  };
1385  /* *INDENT-ON* */
1386  struct
1387  {
1388  u32 dev_instance;
1389  u16 line;
1390  } *ed;
1391 
1392  ed = ELOG_DATA (&vm->elog_main, el);
1393  ed->dev_instance = ad->dev_instance;
1394  ed->line = line;
1395  }
1396 
1397  line--;
1398 
1399  if (ad->flags & AVF_DEVICE_F_RX_INT && ad->rxqs[line].int_mode)
1402 }
1403 
1404 void
1405 avf_delete_if (vlib_main_t * vm, avf_device_t * ad, int with_barrier)
1406 {
1407  vnet_main_t *vnm = vnet_get_main ();
1408  avf_main_t *am = &avf_main;
1409  int i;
1410 
1411  ad->flags &= ~AVF_DEVICE_F_ADMIN_UP;
1412 
1413  if (ad->hw_if_index)
1414  {
1415  if (with_barrier)
1420  if (with_barrier)
1422  }
1423 
1425 
1426  vlib_physmem_free (vm, ad->atq);
1427  vlib_physmem_free (vm, ad->arq);
1428  vlib_physmem_free (vm, ad->atq_bufs);
1429  vlib_physmem_free (vm, ad->arq_bufs);
1430 
1431  /* *INDENT-OFF* */
1432  vec_foreach_index (i, ad->rxqs)
1433  {
1434  avf_rxq_t *rxq = vec_elt_at_index (ad->rxqs, i);
1435  vlib_physmem_free (vm, (void *) rxq->descs);
1436  if (rxq->n_enqueued)
1437  vlib_buffer_free_from_ring (vm, rxq->bufs, rxq->next, rxq->size,
1438  rxq->n_enqueued);
1439  vec_free (rxq->bufs);
1440  }
1441  /* *INDENT-ON* */
1442  vec_free (ad->rxqs);
1443 
1444  /* *INDENT-OFF* */
1445  vec_foreach_index (i, ad->txqs)
1446  {
1447  avf_txq_t *txq = vec_elt_at_index (ad->txqs, i);
1448  vlib_physmem_free (vm, (void *) txq->descs);
1449  if (txq->n_enqueued)
1450  {
1451  u16 first = (txq->next - txq->n_enqueued) & (txq->size -1);
1452  vlib_buffer_free_from_ring (vm, txq->bufs, first, txq->size,
1453  txq->n_enqueued);
1454  }
1455  /* Free the placeholder buffer */
1457  vec_free (txq->bufs);
1458  clib_ring_free (txq->rs_slots);
1459  }
1460  /* *INDENT-ON* */
1461  vec_free (ad->txqs);
1462  vec_free (ad->name);
1463 
1464  clib_error_free (ad->error);
1465  clib_memset (ad, 0, sizeof (*ad));
1466  pool_put_index (am->devices, ad->dev_instance);
1467  clib_mem_free (ad);
1468 }
1469 
1470 static u8
1472 {
1473  clib_error_t *error = 0;
1474 
1475  args->rxq_size = (args->rxq_size == 0) ? AVF_RXQ_SZ : args->rxq_size;
1476  args->txq_size = (args->txq_size == 0) ? AVF_TXQ_SZ : args->txq_size;
1477 
1478  if ((args->rxq_size > AVF_QUEUE_SZ_MAX)
1479  || (args->txq_size > AVF_QUEUE_SZ_MAX))
1480  {
1481  args->rv = VNET_API_ERROR_INVALID_VALUE;
1482  args->error =
1483  clib_error_return (error, "queue size must not be greater than %u",
1485  return 1;
1486  }
1487  if ((args->rxq_size < AVF_QUEUE_SZ_MIN)
1488  || (args->txq_size < AVF_QUEUE_SZ_MIN))
1489  {
1490  args->rv = VNET_API_ERROR_INVALID_VALUE;
1491  args->error =
1492  clib_error_return (error, "queue size must not be smaller than %u",
1494  return 1;
1495  }
1496  if ((args->rxq_size & (args->rxq_size - 1)) ||
1497  (args->txq_size & (args->txq_size - 1)))
1498  {
1499  args->rv = VNET_API_ERROR_INVALID_VALUE;
1500  args->error =
1501  clib_error_return (error, "queue size must be a power of two");
1502  return 1;
1503  }
1504  return 0;
1505 }
1506 
1507 void
1509 {
1510  vnet_main_t *vnm = vnet_get_main ();
1511  avf_main_t *am = &avf_main;
1512  avf_device_t *ad, **adp;
1514  clib_error_t *error = 0;
1515  int i;
1516 
1517  /* check input args */
1518  if (avf_validate_queue_size (args) != 0)
1519  return;
1520 
1521  /* *INDENT-OFF* */
1522  pool_foreach (adp, am->devices) {
1523  if ((*adp)->pci_addr.as_u32 == args->addr.as_u32)
1524  {
1525  args->rv = VNET_API_ERROR_ADDRESS_IN_USE;
1526  args->error =
1527  clib_error_return (error, "%U: %s", format_vlib_pci_addr,
1528  &args->addr, "pci address in use");
1529  return;
1530  }
1531  }
1532  /* *INDENT-ON* */
1533 
1534  pool_get (am->devices, adp);
1535  adp[0] = ad = clib_mem_alloc_aligned (sizeof (avf_device_t),
1537  clib_memset (ad, 0, sizeof (avf_device_t));
1538  ad->dev_instance = adp - am->devices;
1539  ad->per_interface_next_index = ~0;
1540  ad->name = vec_dup (args->name);
1541 
1542  if (args->enable_elog)
1543  ad->flags |= AVF_DEVICE_F_ELOG;
1544 
1545  if ((error = vlib_pci_device_open (vm, &args->addr, avf_pci_device_ids,
1546  &h)))
1547  {
1548  pool_put (am->devices, adp);
1549  clib_mem_free (ad);
1550  args->rv = VNET_API_ERROR_INVALID_INTERFACE;
1551  args->error =
1552  clib_error_return (error, "pci-addr %U", format_vlib_pci_addr,
1553  &args->addr);
1554  return;
1555  }
1556  ad->pci_dev_handle = h;
1557  ad->pci_addr = args->addr;
1558  ad->numa_node = vlib_pci_get_numa_node (vm, h);
1559 
1561 
1562  if ((error = vlib_pci_bus_master_enable (vm, h)))
1563  goto error;
1564 
1565  if ((error = vlib_pci_map_region (vm, h, 0, &ad->bar0)))
1566  goto error;
1567 
1569  AVF_MBOX_LEN,
1571  ad->numa_node);
1572  if (ad->atq == 0)
1573  {
1574  error = vlib_physmem_last_error (vm);
1575  goto error;
1576  }
1577 
1578  if ((error = vlib_pci_map_dma (vm, h, ad->atq)))
1579  goto error;
1580 
1582  AVF_MBOX_LEN,
1584  ad->numa_node);
1585  if (ad->arq == 0)
1586  {
1587  error = vlib_physmem_last_error (vm);
1588  goto error;
1589  }
1590 
1591  if ((error = vlib_pci_map_dma (vm, h, ad->arq)))
1592  goto error;
1593 
1595  AVF_MBOX_LEN,
1597  ad->numa_node);
1598  if (ad->atq_bufs == 0)
1599  {
1600  error = vlib_physmem_last_error (vm);
1601  goto error;
1602  }
1603 
1604  if ((error = vlib_pci_map_dma (vm, h, ad->atq_bufs)))
1605  goto error;
1606 
1608  AVF_MBOX_LEN,
1610  ad->numa_node);
1611  if (ad->arq_bufs == 0)
1612  {
1613  error = vlib_physmem_last_error (vm);
1614  goto error;
1615  }
1616 
1617  if ((error = vlib_pci_map_dma (vm, h, ad->arq_bufs)))
1618  goto error;
1619 
1621  ad->flags |= AVF_DEVICE_F_VA_DMA;
1622 
1623  if ((error = avf_device_init (vm, am, ad, args)))
1624  goto error;
1625 
1626  if ((error = vlib_pci_register_msix_handler (vm, h, 0, 1,
1627  &avf_irq_0_handler)))
1628  goto error;
1629 
1630  if ((error = vlib_pci_register_msix_handler (vm, h, 1, ad->n_rx_irqs,
1631  &avf_irq_n_handler)))
1632  goto error;
1633 
1634  if ((error = vlib_pci_enable_msix_irq (vm, h, 0, ad->n_rx_irqs + 1)))
1635  goto error;
1636 
1637  if ((error = vlib_pci_intr_enable (vm, h)))
1638  goto error;
1639 
1640  /* create interface */
1641  error = ethernet_register_interface (vnm, avf_device_class.index,
1642  ad->dev_instance, ad->hwaddr,
1644 
1645  if (error)
1646  goto error;
1647 
1648  /* Indicate ability to support L3 DMAC filtering and
1649  * initialize interface to L3 non-promisc mode */
1651  hi->flags |=
1655  ethernet_set_flags (vnm, ad->hw_if_index,
1657 
1659  args->sw_if_index = ad->sw_if_index = sw->sw_if_index;
1660 
1664  avf_input_node.index);
1665 
1666  for (i = 0; i < ad->n_rx_queues; i++)
1668 
1669  if (pool_elts (am->devices) == 1)
1672 
1673  return;
1674 
1675 error:
1676  avf_delete_if (vm, ad, /* with_barrier */ 0);
1677  args->rv = VNET_API_ERROR_INVALID_INTERFACE;
1678  args->error = clib_error_return (error, "pci-addr %U",
1679  format_vlib_pci_addr, &args->addr);
1680  avf_log_err (ad, "error: %U", format_clib_error, args->error);
1681 }
1682 
1683 static clib_error_t *
1685 {
1686  vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1688  uword is_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
1689 
1690  if (ad->flags & AVF_DEVICE_F_ERROR)
1691  return clib_error_return (0, "device is in error state");
1692 
1693  if (is_up)
1694  {
1697  ad->flags |= AVF_DEVICE_F_ADMIN_UP;
1698  }
1699  else
1700  {
1702  ad->flags &= ~AVF_DEVICE_F_ADMIN_UP;
1703  }
1704  return 0;
1705 }
1706 
1707 static clib_error_t *
1710 {
1711  vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
1713  avf_rxq_t *rxq = vec_elt_at_index (ad->rxqs, qid);
1714 
1715  if (mode == VNET_HW_IF_RX_MODE_POLLING)
1716  {
1717  if (rxq->int_mode == 0)
1718  return 0;
1719  if (ad->feature_bitmap & VIRTCHNL_VF_OFFLOAD_WB_ON_ITR)
1721  else
1723  rxq->int_mode = 0;
1724  }
1725  else
1726  {
1727  if (rxq->int_mode == 1)
1728  return 0;
1729  if (ad->n_rx_irqs != ad->n_rx_queues)
1730  return clib_error_return (0, "not enough interrupt lines");
1731  rxq->int_mode = 1;
1733  }
1734 
1735  return 0;
1736 }
1737 
1738 static void
1740  u32 node_index)
1741 {
1742  vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
1744 
1745  /* Shut off redirection */
1746  if (node_index == ~0)
1747  {
1748  ad->per_interface_next_index = node_index;
1749  return;
1750  }
1751 
1753  vlib_node_add_next (vlib_get_main (), avf_input_node.index, node_index);
1754 }
1755 
1756 static clib_error_t *
1758  const u8 * address, u8 is_add)
1759 {
1761  avf_process_req_t req;
1762 
1763  req.dev_instance = hw->dev_instance;
1765  req.is_add = is_add;
1766  clib_memcpy (req.eth_addr, address, 6);
1767 
1768  return avf_process_request (vm, &req);
1769 }
1770 
1771 static char *avf_tx_func_error_strings[] = {
1772 #define _(n,s) s,
1774 #undef _
1775 };
1776 
1777 static void
1779 {
1780  avf_device_t *ad = avf_get_device (instance);
1782  &ad->eth_stats, sizeof (ad->eth_stats));
1783 }
1784 
1785 /* *INDENT-OFF* */
1787 {
1788  .name = "Adaptive Virtual Function (AVF) interface",
1789  .clear_counters = avf_clear_hw_interface_counters,
1790  .format_device = format_avf_device,
1791  .format_device_name = format_avf_device_name,
1792  .admin_up_down_function = avf_interface_admin_up_down,
1793  .rx_mode_change_function = avf_interface_rx_mode_change,
1794  .rx_redirect_to_node = avf_set_interface_next_node,
1795  .mac_addr_add_del_function = avf_add_del_mac_address,
1796  .tx_function_n_errors = AVF_TX_N_ERROR,
1797  .tx_function_error_strings = avf_tx_func_error_strings,
1798 };
1799 /* *INDENT-ON* */
1800 
1801 clib_error_t *
1803 {
1804  avf_main_t *am = &avf_main;
1806 
1809 
1810  return 0;
1811 }
1812 
1813 /* *INDENT-OFF* */
1815 {
1816  .runs_after = VLIB_INITS ("pci_bus_init"),
1817 };
1818 /* *INDENT-OFF* */
1819 
1820 /*
1821  * fd.io coding-style-patch-verification: ON
1822  *
1823  * Local Variables:
1824  * eval: (c-set-style "gnu")
1825  * End:
1826  */
#define AVF_TXQ_SZ
Definition: device.c:29
clib_error_t * avf_op_get_vf_resources(vlib_main_t *vm, avf_device_t *ad, virtchnl_vf_resource_t *res)
Definition: device.c:554
vlib_log_class_t class
Definition: log.h:84
vlib_node_registration_t avf_process_node
(constructor) VLIB_REGISTER_NODE (avf_process_node)
Definition: device.c:1326
u8 int_mode
Definition: avf.h:165
#define vec_foreach_index(var, v)
Iterate over vector indices.
#define AVF_ARQLEN
Definition: virtchnl.h:47
virtchnl_queue_pair_info_t qpair[1]
Definition: virtchnl.h:311
u32 hw_if_index
Definition: avf.h:191
static clib_error_t * vlib_pci_intr_enable(vlib_main_t *vm, vlib_pci_dev_handle_t h)
Definition: pci.h:239
#define PCI_DEVICE_ID_INTEL_AVF
Definition: device.c:33
#define AVF_ATQH
Definition: virtchnl.h:40
#define clib_min(x, y)
Definition: clib.h:328
#define pool_foreach_index(i, v)
Definition: pool.h:569
static void avf_irq_0_set_state(avf_device_t *ad, avf_irq_state_t state)
Definition: device.c:67
u32 ctx_desc_placeholder_bi
Definition: avf.h:175
static uword random_default_seed(void)
Default random seed (unix/linux user-mode)
Definition: random.h:91
static clib_error_t * vlib_pci_bus_master_enable(vlib_main_t *vm, vlib_pci_dev_handle_t h)
Definition: pci.h:271
static void * vlib_physmem_alloc_aligned_on_numa(vlib_main_t *vm, uword n_bytes, uword alignment, u32 numa_node)
Definition: physmem_funcs.h:63
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
Definition: node_funcs.h:751
void avf_arq_slot_init(avf_device_t *ad, u16 slot)
Definition: device.c:353
vl_api_wireguard_peer_flags_t flags
Definition: wireguard.api:105
clib_error_t * avf_send_to_pf(vlib_main_t *vm, avf_device_t *ad, virtchnl_ops_t op, void *in, int in_len, void *out, int out_len)
Definition: device.c:410
void avf_create_if(vlib_main_t *vm, avf_create_if_args_t *args)
Definition: device.c:1508
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
Definition: node_funcs.h:656
void ethernet_delete_interface(vnet_main_t *vnm, u32 hw_if_index)
Definition: interface.c:393
VLIB_REGISTER_LOG_CLASS(avf_log)
#define AVF_ATQBAH
Definition: virtchnl.h:45
clib_error_t * avf_device_init(vlib_main_t *vm, avf_main_t *am, avf_device_t *ad, avf_create_if_args_t *args)
Definition: device.c:911
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
clib_error_t * error
Definition: avf.h:231
#define pool_foreach(VAR, POOL)
Iterate through pool.
Definition: pool.h:527
#define avf_log_warn(dev, f,...)
Definition: avf.h:90
#define AVF_AQ_ENQ_SUSPEND_TIME
Definition: avf.h:35
clib_error_t * avf_op_config_vsi_queues(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:668
clib_error_t * avf_op_version(vlib_main_t *vm, avf_device_t *ad, virtchnl_version_info_t *ver)
Definition: device.c:532
u64 atq_bufs_pa
Definition: avf.h:208
static uword vlib_buffer_get_pa(vlib_main_t *vm, vlib_buffer_t *b)
Definition: buffer_funcs.h:457
virtchnl_vsi_type_t vsi_type
Definition: virtchnl.h:165
#define AVF_SEND_TO_PF_SUSPEND_TIME
Definition: avf.h:41
unsigned long u64
Definition: types.h:89
void vlib_pci_device_close(vlib_main_t *vm, vlib_pci_dev_handle_t h)
Definition: pci.c:1311
static clib_error_t * avf_process_request(vlib_main_t *vm, avf_process_req_t *req)
Definition: device.c:1196
virtchnl_vector_map_t vecmap[1]
Definition: virtchnl.h:339
#define clib_memcpy_fast(a, b, c)
Definition: string.h:81
u16 n_rx_irqs
Definition: avf.h:219
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:334
#define clib_ring_new_aligned(ring, size, align)
Definition: ring.h:53
virtchnl_link_speed_t link_speed
Definition: avf.h:223
#define AVF_ARQBAH
Definition: virtchnl.h:39
static uword avf_dma_addr(vlib_main_t *vm, avf_device_t *ad, void *p)
Definition: device.c:366
static clib_error_t * vlib_physmem_last_error(struct vlib_main_t *vm)
clib_error_t * avf_aq_desc_enq(vlib_main_t *vm, avf_device_t *ad, avf_aq_desc_t *dt, void *data, int len)
Definition: device.c:128
avf_process_req_type_t type
Definition: avf.h:252
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
#define AVF_QRX_TAIL(q)
Definition: virtchnl.h:51
#define AVF_ARQT
Definition: virtchnl.h:43
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:592
format_function_t format_avf_device
Definition: avf.h:306
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:630
static void avf_irq_n_handler(vlib_main_t *vm, vlib_pci_dev_handle_t h, u16 line)
Definition: device.c:1371
vlib_pci_addr_t addr
Definition: avf.h:287
struct virtchnl_pf_event_t::@33::@35 link_event_adv
clib_error_t * avf_init(vlib_main_t *vm)
Definition: device.c:1802
#define AVF_AQ_F_SI
Definition: virtchnl.h:61
u32 dev_instance
Definition: avf.h:189
clib_error_t * vlib_pci_enable_msix_irq(vlib_main_t *vm, vlib_pci_dev_handle_t h, u16 start, u16 count)
Definition: pci.c:895
vlib_main_t * vm
Definition: in2out_ed.c:1580
#define AVF_QTX_TAIL(q)
Definition: virtchnl.h:50
clib_error_t * avf_rxq_init(vlib_main_t *vm, avf_device_t *ad, u16 qid, u16 rxq_size)
Definition: device.c:246
virtchnl_link_speed_t
Definition: virtchnl.h:205
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:520
#define ETHERNET_INTERFACE_FLAG_DEFAULT_L3
Definition: ethernet.h:160
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, vnet_hw_interface_flags_t flags)
Definition: interface.c:509
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:251
volatile u32 * qtx_tail
Definition: avf.h:172
#define AVF_ATQLEN
Definition: virtchnl.h:41
clib_error_t * error
Definition: avf.h:257
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
Definition: node_funcs.h:1173
void avf_process_one_device(vlib_main_t *vm, avf_device_t *ad, int is_irq)
Definition: device.c:1034
unsigned char u8
Definition: types.h:56
vnet_device_class_t avf_device_class
#define AVF_ARQH
Definition: virtchnl.h:44
static clib_error_t * avf_interface_rx_mode_change(vnet_main_t *vnm, u32 hw_if_index, u32 qid, vnet_hw_if_rx_mode mode)
Definition: device.c:1708
u8 data[128]
Definition: ipsec_types.api:90
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
double f64
Definition: types.h:142
#define vlib_worker_thread_barrier_sync(X)
Definition: threads.h:205
void avf_delete_if(vlib_main_t *vm, avf_device_t *ad, int with_barrier)
Definition: device.c:1405
virtchnl_ops_t
Definition: virtchnl.h:103
static vnet_sw_interface_t * vnet_get_hw_sw_interface(vnet_main_t *vnm, u32 hw_if_index)
#define clib_memcpy(d, s, n)
Definition: string.h:180
u8 buffer_pool_index
Definition: avf.h:166
static uword vlib_process_suspend(vlib_main_t *vm, f64 dt)
Suspend a vlib cooperative multi-tasking thread for a period of time.
Definition: node_funcs.h:482
u32 calling_process_index
Definition: avf.h:254
#define AVF_AQ_F_DD
Definition: virtchnl.h:53
#define AVF_RESET_SUSPEND_TIME
Definition: avf.h:38
u16 * rs_slots
Definition: avf.h:180
#define AVFINT_ICR0_ENA1
Definition: virtchnl.h:37
VNET_DEVICE_CLASS(af_xdp_device_class)
u8 * format_ethernet_address(u8 *s, va_list *args)
Definition: format.c:44
avf_irq_state_t
Definition: device.c:59
clib_error_t * vlib_pci_map_dma(vlib_main_t *vm, vlib_pci_dev_handle_t h, void *ptr)
Definition: pci.c:1232
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
Definition: node_funcs.h:579
clib_spinlock_t lock
Definition: avf.h:176
#define AVF_SEND_TO_PF_MAX_WAIT_TIME
Definition: avf.h:42
static uword pow2_mask(uword x)
Definition: clib.h:238
static u32 avf_reg_read(avf_device_t *ad, u32 addr)
Definition: avf.h:363
static_always_inline void vnet_device_input_set_interrupt_pending(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id)
Definition: devices.h:127
static void avf_irq_0_handler(vlib_main_t *vm, vlib_pci_dev_handle_t h, u16 line)
Definition: device.c:1334
vnet_hw_interface_flags_t flags
Definition: interface.h:538
volatile u32 * qrx_tail
Definition: avf.h:159
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define clib_error_return(e, args...)
Definition: error.h:99
static void avf_set_interface_next_node(vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
Definition: device.c:1739
const cJSON *const b
Definition: cJSON.h:255
static const char * virtchnl_event_names[]
Definition: device.c:53
unsigned int u32
Definition: types.h:88
clib_error_t * avf_op_add_del_eth_addr(vlib_main_t *vm, avf_device_t *ad, u8 count, u8 *macs, int is_add)
Definition: device.c:755
vlib_log_class_registration_t avf_log
vlib_pci_dev_handle_t pci_dev_handle
Definition: avf.h:192
int is_enable
Definition: avf.h:256
clib_error_t * avf_op_config_rss_lut(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:592
virtchnl_ether_addr_t list[1]
Definition: virtchnl.h:354
void * arq_bufs
Definition: avf.h:207
avf_aq_desc_t * arq
Definition: avf.h:205
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:65
static void vlib_buffer_free_from_ring(vlib_main_t *vm, u32 *ring, u32 start, u32 ring_size, u32 n_buffers)
Free buffers from ring.
Definition: buffer_funcs.h:984
static u32 avf_flag_change(vnet_main_t *vnm, vnet_hw_interface_t *hw, u32 flags)
Definition: device.c:1219
static heap_elt_t * first(heap_header_t *h)
Definition: heap.c:59
Definition: cJSON.c:84
u8 * name
Definition: avf.h:195
virtchnl_eth_stats_t last_cleared_eth_stats
Definition: avf.h:228
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:1015
void vlib_pci_set_private_data(vlib_main_t *vm, vlib_pci_dev_handle_t h, uword private_data)
Definition: pci.c:155
static u8 avf_validate_queue_size(avf_create_if_args_t *args)
Definition: device.c:1471
static u32 avf_get_u32(void *start, int offset)
Definition: avf.h:317
virtchnl_txq_info_t txq
Definition: virtchnl.h:302
#define AVF_ATQT
Definition: virtchnl.h:48
unsigned short u16
Definition: types.h:57
#define AVF_RESET_MAX_WAIT_TIME
Definition: avf.h:39
#define AVF_QUEUE_SZ_MAX
Definition: avf.h:32
vec_header_t h
Definition: buffer.c:322
static void avf_clear_hw_interface_counters(u32 instance)
Definition: device.c:1778
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:301
#define vec_dup(V)
Return copy of vector (no header, no alignment)
Definition: vec.h:429
static void avf_adminq_init(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:373
clib_error_t * vlib_pci_register_msix_handler(vlib_main_t *vm, vlib_pci_dev_handle_t h, u32 start, u32 count, pci_msix_handler_function_t *msix_handler)
Definition: pci.c:838
u64 qword[4]
Definition: avf.h:134
#define ELOG_DATA(em, f)
Definition: elog.h:484
#define AVF_AQ_F_RD
Definition: virtchnl.h:58
#define VIRTCHNL_VERSION_MAJOR
Definition: virtchnl.h:21
uword vlib_pci_get_private_data(vlib_main_t *vm, vlib_pci_dev_handle_t h)
Definition: pci.c:148
clib_error_t * avf_op_disable_vlan_stripping(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:639
static void avf_reg_flush(avf_device_t *ad)
Definition: avf.h:369
u32 vlib_pci_dev_handle_t
Definition: pci.h:97
#define AVFINT_ICR0
Definition: virtchnl.h:36
vl_api_tunnel_mode_t mode
Definition: gre.api:48
clib_error_t * avf_device_reset(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:824
#define PCI_DEVICE_ID_INTEL_X710_VF
Definition: device.c:34
clib_error_t * avf_op_config_irq_map(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:724
avf_device_t ** devices
Definition: avf.h:279
#define PCI_VENDOR_ID_INTEL
Definition: device.c:32
u8 len
Definition: ip_types.api:103
clib_error_t * avf_request_queues(vlib_main_t *vm, avf_device_t *ad, u16 num_queue_pairs)
Definition: device.c:862
u16 n_rx_queues
Definition: avf.h:201
static_always_inline u32 vlib_buffer_get_default_data_size(vlib_main_t *vm)
Definition: buffer_funcs.h:96
u8 slot
Definition: pci_types.api:22
u8 hwaddr[6]
Definition: avf.h:216
u16 atq_next_slot
Definition: avf.h:210
u32 vlib_pci_get_numa_node(vlib_main_t *vm, vlib_pci_dev_handle_t h)
Definition: pci.c:170
#define AVF_AQ_F_BUF
Definition: virtchnl.h:60
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:170
static void vlib_process_signal_event_pointer(vlib_main_t *vm, uword node_index, uword type_opaque, void *data)
Definition: node_funcs.h:1024
u32 numa_node
Definition: avf.h:193
clib_error_t * avf_op_config_promisc_mode(vlib_main_t *vm, avf_device_t *ad, int is_enable)
Definition: device.c:648
static void vlib_physmem_free(vlib_main_t *vm, void *p)
Definition: physmem_funcs.h:89
vlib_node_registration_t avf_input_node
(constructor) VLIB_REGISTER_NODE (avf_input_node)
Definition: input.c:465
#define avf_log_debug(dev, f,...)
Definition: avf.h:95
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
static clib_error_t * avf_add_del_mac_address(vnet_hw_interface_t *hw, const u8 *address, u8 is_add)
Definition: device.c:1757
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:380
Definition: avf.h:156
elog_main_t elog_main
Definition: main.h:224
avf_tx_desc_t * descs
Definition: avf.h:177
#define ETHERNET_INTERFACE_FLAG_ACCEPT_ALL
Definition: ethernet.h:163
static void avf_irq_n_set_state(avf_device_t *ad, u8 line, avf_irq_state_t state)
Definition: device.c:96
#define ELOG_TYPE_DECLARE(f)
Definition: elog.h:442
virtchnl_ops_t v_opcode
Definition: virtchnl.h:249
static_always_inline avf_device_t * avf_get_device(u32 dev_instance)
Definition: avf.h:311
#define AVFINT_DYN_CTL0
Definition: virtchnl.h:38
u16 vsi_id
Definition: avf.h:214
u32 per_interface_next_index
Definition: avf.h:187
u32 feature_bitmap
Definition: avf.h:215
virtchnl_status_code_t v_retval
Definition: virtchnl.h:254
u32 * bufs
Definition: avf.h:178
#define AVF_ITR_INT
Definition: device.c:30
clib_error_t * avf_op_enable_queues(vlib_main_t *vm, avf_device_t *ad, u32 rx, u32 tx)
Definition: device.c:784
#define pool_put_index(p, i)
Free pool element with given index.
Definition: pool.h:330
#define ASSERT(truth)
#define AVF_RXQ_SZ
Definition: device.c:28
avf_aq_desc_t * atq
Definition: avf.h:204
void vnet_hw_interface_assign_rx_thread(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id, uword thread_index)
Definition: devices.c:139
manual_print typedef address
Definition: ip_types.api:96
u32 flags
Definition: avf.h:186
union virtchnl_pf_event_t::@33 event_data
#define AVFINT_DYN_CTLN(x)
Definition: virtchnl.h:35
Definition: avf.h:169
u32 * bufs
Definition: avf.h:163
struct virtchnl_pf_event_t::@33::@34 link_event
void * bar0
Definition: avf.h:194
static void clib_mem_free(void *p)
Definition: mem.h:311
#define AVF_MBOX_BUF_SZ
Definition: device.c:27
u16 n_enqueued
Definition: avf.h:179
clib_error_t * avf_txq_init(vlib_main_t *vm, avf_device_t *ad, u16 qid, u16 txq_size)
Definition: device.c:297
u16 n_enqueued
Definition: avf.h:164
u8 * format_hex_bytes_no_wrap(u8 *s, va_list *va)
Definition: std-formats.c:112
virtchnl_pf_event_t * events
Definition: avf.h:212
virtchnl_event_codes_t event
Definition: virtchnl.h:215
#define AVF_AQ_ENQ_MAX_WAIT_TIME
Definition: avf.h:36
static void avf_process_handle_request(vlib_main_t *vm, avf_process_req_t *req)
Definition: device.c:1179
static void avf_reg_write(avf_device_t *ad, u32 addr, u32 val)
Definition: avf.h:357
static uword pointer_to_uword(const void *p)
Definition: types.h:131
static char * avf_tx_func_error_strings[]
Definition: device.c:1771
#define clib_max(x, y)
Definition: clib.h:321
virtchnl_eth_stats_t eth_stats
Definition: avf.h:227
void * atq_bufs
Definition: avf.h:206
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
vl_api_ip4_address_t hi
Definition: arp.api:37
#define AVFGEN_RSTAT
Definition: virtchnl.h:49
u16 num_queue_pairs
Definition: avf.h:217
u16 next
Definition: avf.h:173
#define PCI_DEVICE_ID_INTEL_X722_VF
Definition: device.c:35
u8 eth_addr[6]
Definition: avf.h:255
clib_error_t * avf_op_config_rss_key(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:615
u32 dev_instance
Definition: avf.h:253
virtchnl_rxq_info_t rxq
Definition: virtchnl.h:303
static u64 vlib_physmem_get_pa(vlib_main_t *vm, void *mem)
#define AVF_ARQBAL
Definition: virtchnl.h:42
u32 rss_lut_size
Definition: avf.h:222
u16 n_tx_queues
Definition: avf.h:200
#define AVF_QUEUE_SZ_MIN
Definition: avf.h:33
static u32 vlib_get_current_process_node_index(vlib_main_t *vm)
Definition: node_funcs.h:459
#define AVF_AQ_F_CMP
Definition: virtchnl.h:54
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
clib_error_t * ethernet_register_interface(vnet_main_t *vnm, u32 dev_class_index, u32 dev_instance, const u8 *address, u32 *hw_if_index_return, ethernet_flag_change_function_t flag_change)
Definition: interface.c:348
u32 instance
Definition: gre.api:51
clib_error_t * avf_cmd_rx_ctl_reg_write(vlib_main_t *vm, avf_device_t *ad, u32 reg, u32 val)
Definition: device.c:215
format_function_t format_avf_device_name
Definition: avf.h:307
avf_main_t avf_main
Definition: device.c:43
#define foreach_virtchnl_op
Definition: virtchnl.h:66
VLIB buffer representation.
Definition: buffer.h:102
#define foreach_avf_tx_func_error
Definition: avf.h:395
u64 uword
Definition: types.h:112
u16 size
Definition: avf.h:161
u16 arq_next_slot
Definition: avf.h:211
#define clib_error_free(e)
Definition: error.h:86
clib_error_t * vlib_pci_map_region(vlib_main_t *vm, vlib_pci_dev_handle_t h, u32 resource, void **result)
Definition: pci.c:1182
clib_error_t * avf_op_get_stats(vlib_main_t *vm, avf_device_t *ad, virtchnl_eth_stats_t *es)
Definition: device.c:810
avf_rxq_t * rxqs
Definition: avf.h:198
virtchnl_vsi_resource_t vsi_res[1]
Definition: virtchnl.h:179
int vnet_hw_interface_unassign_rx_thread(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id)
Definition: devices.c:188
int vlib_pci_supports_virtual_addr_dma(vlib_main_t *vm, vlib_pci_dev_handle_t h)
Definition: pci.c:1243
static void * clib_mem_alloc_aligned(uword size, uword align)
Definition: mem.h:261
clib_error_t * error
Definition: avf.h:296
static uword avf_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: device.c:1252
static u32 random_u32(u32 *seed)
32-bit random number generator
Definition: random.h:69
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
Definition: threads.c:1561
avf_per_thread_data_t * per_thread_data
Definition: avf.h:280
static uword vlib_buffer_get_va(vlib_buffer_t *b)
Definition: buffer.h:221
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
u16 size
Definition: avf.h:174
vlib_pci_addr_t pci_addr
Definition: avf.h:224
vl_api_dhcp_client_state_t state
Definition: dhcp.api:201
vnet_hw_if_rx_mode
Definition: interface.h:53
u32 sw_if_index
Definition: avf.h:190
#define ETHERNET_MAX_PACKET_BYTES
Definition: ethernet.h:133
#define vec_foreach(var, vec)
Vector iterator.
#define vlib_log_err(...)
Definition: log.h:132
u64 arq_bufs_pa
Definition: avf.h:209
u8 count
Definition: dhcp.api:208
#define CLIB_MEMORY_BARRIER()
Definition: clib.h:133
static clib_error_t * avf_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: device.c:1684
static void vlib_buffer_free_one(vlib_main_t *vm, u32 buffer_index)
Free one buffer Shorthand to free a single buffer chain.
Definition: buffer_funcs.h:970
#define avf_log_err(dev, f,...)
Definition: avf.h:85
#define AVF_ATQBAL
Definition: virtchnl.h:46
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
#define VIRTCHNL_VERSION_MINOR
Definition: virtchnl.h:22
static u8 vlib_buffer_pool_get_default_for_numa(vlib_main_t *vm, u32 numa_node)
Definition: buffer_funcs.h:199
#define clib_ring_free(f)
Definition: ring.h:59
#define AVF_MBOX_LEN
Definition: device.c:26
clib_error_t * vlib_pci_device_open(vlib_main_t *vm, vlib_pci_addr_t *addr, pci_device_id_t ids[], vlib_pci_dev_handle_t *handle)
Definition: pci.c:1251
u16 next
Definition: avf.h:160
__clib_export u8 * format_clib_error(u8 *s, va_list *va)
Definition: error.c:191
#define VLIB_INITS(...)
Definition: init.h:357
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85
static void vnet_hw_interface_set_link_speed(vnet_main_t *vnm, u32 hw_if_index, u32 link_speed)
static void vnet_hw_interface_set_input_node(vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
Definition: devices.h:79
#define clib_panic(format, args...)
Definition: error.h:72
avf_txq_t * txqs
Definition: avf.h:199
avf_rx_desc_t * descs
Definition: avf.h:162
u16 vendor_id
Definition: pci.h:127
format_function_t format_vlib_pci_addr
Definition: pci.h:326
#define AVF_AQ_F_ERR
Definition: virtchnl.h:55
static __clib_warn_unused_result u32 vlib_buffer_alloc_from_pool(vlib_main_t *vm, u32 *buffers, u32 n_buffers, u8 buffer_pool_index)
Allocate buffers from specific pool into supplied array.
Definition: buffer_funcs.h:566
u32 ethernet_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:441
u16 max_vectors
Definition: avf.h:218
u32 rss_key_size
Definition: avf.h:221
u16 max_mtu
Definition: avf.h:220
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:127