FD.io VPP  v18.04-17-g3a0d853
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 <vlib/unix/unix.h>
20 #include <vlib/pci/pci.h>
21 #include <vnet/ethernet/ethernet.h>
22 
23 #include <avf/avf.h>
24 
25 #define AVF_MBOX_LEN 64
26 #define AVF_MBOX_BUF_SZ 512
27 #define AVF_RXQ_SZ 512
28 #define AVF_TXQ_SZ 512
29 #define AVF_ITR_INT 8160
30 
31 #define PCI_VENDOR_ID_INTEL 0x8086
32 #define PCI_DEVICE_ID_INTEL_AVF 0x1889
33 #define PCI_DEVICE_ID_INTEL_X710_VF 0x154c
34 #define PCI_DEVICE_ID_INTEL_X722_VF 0x37cd
35 
37 
38 static pci_device_id_t avf_pci_device_ids[] = {
40  {.vendor_id = PCI_VENDOR_ID_INTEL,.device_id = PCI_DEVICE_ID_INTEL_X710_VF},
41  {0},
42 };
43 
44 //#define avf_log_debug(fmt, ...) fformat(stderr, "%s: " fmt "\n", __func__, __VA_ARGS__)
45 #define avf_log_debug(fmt, ...)
46 
47 static inline void
49 {
50  u32 dyn_ctl0 = 0, icr0_ena = 0;
51 
52  dyn_ctl0 |= (3 << 3); /* 11b = No ITR update */
53 
54  avf_reg_write (ad, AVFINT_ICR0_ENA1, icr0_ena);
55  avf_reg_write (ad, AVFINT_DYN_CTL0, dyn_ctl0);
56  avf_reg_flush (ad);
57 }
58 
59 static inline void
61 {
62  u32 dyn_ctl0 = 0, icr0_ena = 0;
63 
64  icr0_ena |= (1 << 30); /* [30] Admin Queue Enable */
65 
66  dyn_ctl0 |= (1 << 0); /* [0] Interrupt Enable */
67  dyn_ctl0 |= (1 << 1); /* [1] Clear PBA */
68  //dyn_ctl0 |= (3 << 3); /* [4:3] ITR Index, 11b = No ITR update */
69  dyn_ctl0 |= ((AVF_ITR_INT / 2) << 5); /* [16:5] ITR Interval in 2us steps */
70 
71  avf_irq_0_disable (ad);
72  avf_reg_write (ad, AVFINT_ICR0_ENA1, icr0_ena);
73  avf_reg_write (ad, AVFINT_DYN_CTL0, dyn_ctl0);
74  avf_reg_flush (ad);
75 }
76 
77 static inline void
79 {
80  u32 dyn_ctln = 0;
81 
82  avf_reg_write (ad, AVFINT_DYN_CTLN (line), dyn_ctln);
83  avf_reg_flush (ad);
84 }
85 
86 static inline void
88 {
89  u32 dyn_ctln = 0;
90 
91  dyn_ctln |= (1 << 0); /* [0] Interrupt Enable */
92  dyn_ctln |= (1 << 1); /* [1] Clear PBA */
93  dyn_ctln |= ((AVF_ITR_INT / 2) << 5); /* [16:5] ITR Interval in 2us steps */
94 
95  avf_irq_n_disable (ad, line);
96  avf_reg_write (ad, AVFINT_DYN_CTLN (line), dyn_ctln);
97  avf_reg_flush (ad);
98 }
99 
100 
101 clib_error_t *
103  void *data, int len)
104 {
105  clib_error_t *err = 0;
106  avf_aq_desc_t *d, dc;
107  int n_retry = 5;
108 
109  d = &ad->atq[ad->atq_next_slot];
110  clib_memcpy (d, dt, sizeof (avf_aq_desc_t));
111  d->flags |= AVF_AQ_F_RD | AVF_AQ_F_SI;
112  if (len)
113  d->datalen = len;
114  if (len)
115  {
116  u64 pa;
117  pa = ad->atq_bufs_pa + ad->atq_next_slot * AVF_MBOX_BUF_SZ;
118  d->addr_hi = (u32) (pa >> 32);
119  d->addr_lo = (u32) pa;
121  len);
122  d->flags |= AVF_AQ_F_BUF;
123  }
124 
125  if (ad->flags & AVF_DEVICE_F_ELOG)
126  clib_memcpy (&dc, d, sizeof (avf_aq_desc_t));
127 
129  avf_log_debug ("%U", format_hexdump, data, len);
130  ad->atq_next_slot = (ad->atq_next_slot + 1) % AVF_MBOX_LEN;
132  avf_reg_flush (ad);
133 
134 retry:
135  vlib_process_suspend (vm, 10e-6);
136 
137  if (((d->flags & AVF_AQ_F_DD) == 0) || ((d->flags & AVF_AQ_F_CMP) == 0))
138  {
139  if (--n_retry == 0)
140  {
141  err = clib_error_return (0, "adminq enqueue timeout [opcode 0x%x]",
142  d->opcode);
143  goto done;
144  }
145  goto retry;
146  }
147 
148  clib_memcpy (dt, d, sizeof (avf_aq_desc_t));
149  if (d->flags & AVF_AQ_F_ERR)
150  return clib_error_return (0, "adminq enqueue error [opcode 0x%x, retval "
151  "%d]", d->opcode, d->retval);
152 
153 done:
154  if (ad->flags & AVF_DEVICE_F_ELOG)
155  {
156  /* *INDENT-OFF* */
157  ELOG_TYPE_DECLARE (el) =
158  {
159  .format = "avf[%d] aq enq: s_flags 0x%x r_flags 0x%x opcode 0x%x "
160  "datalen %d retval %d",
161  .format_args = "i4i2i2i2i2i2",
162  };
163  struct
164  {
165  u32 dev_instance;
166  u16 s_flags;
167  u16 r_flags;
168  u16 opcode;
169  u16 datalen;
170  u16 retval;
171  } *ed;
172  ed = ELOG_DATA (&vm->elog_main, el);
173  ed->dev_instance = ad->dev_instance;
174  ed->s_flags = dc.flags;
175  ed->r_flags = d->flags;
176  ed->opcode = dc.opcode;
177  ed->datalen = dc.datalen;
178  ed->retval = d->retval;
179  /* *INDENT-ON* */
180  }
181 
182  return err;
183 }
184 
185 clib_error_t *
187  u32 val)
188 {
189  clib_error_t *err;
190  avf_aq_desc_t d = {.opcode = 0x207,.param1 = reg,.param3 = val };
191  err = avf_aq_desc_enq (vm, ad, &d, 0, 0);
192 
193  if (ad->flags & AVF_DEVICE_F_ELOG)
194  {
195  /* *INDENT-OFF* */
196  ELOG_TYPE_DECLARE (el) =
197  {
198  .format = "avf[%d] rx ctl reg write: reg 0x%x val 0x%x ",
199  .format_args = "i4i4i4",
200  };
201  struct
202  {
203  u32 dev_instance;
204  u32 reg;
205  u32 val;
206  } *ed;
207  ed = ELOG_DATA (&vm->elog_main, el);
208  ed->dev_instance = ad->dev_instance;
209  ed->reg = reg;
210  ed->val = val;
211  /* *INDENT-ON* */
212  }
213  return err;
214 }
215 
216 clib_error_t *
218 {
219  avf_main_t *am = &avf_main;
220  avf_rxq_t *rxq;
221  clib_error_t *error = 0;
222  u32 n_alloc, i;
223 
225  rxq = vec_elt_at_index (ad->rxqs, qid);
226  rxq->size = AVF_RXQ_SZ;
227  rxq->next = 0;
228  rxq->descs = vlib_physmem_alloc_aligned (vm, am->physmem_region, &error,
229  rxq->size * sizeof (avf_rx_desc_t),
231  memset (rxq->descs, 0, rxq->size * sizeof (avf_rx_desc_t));
233  rxq->qrx_tail = ad->bar0 + AVF_QRX_TAIL (qid);
234 
235  n_alloc = vlib_buffer_alloc (vm, rxq->bufs, rxq->size - 8);
236 
237  if (n_alloc == 0)
238  return clib_error_return (0, "buffer allocation error");
239 
240  rxq->n_bufs = n_alloc;
241  avf_rx_desc_t *d = rxq->descs;
242  for (i = 0; i < n_alloc; i++)
243  {
244  if (ad->flags & AVF_DEVICE_F_IOVA)
245  {
246  vlib_buffer_t *b = vlib_get_buffer (vm, rxq->bufs[i]);
247  d->qword[0] = pointer_to_uword (b->data);
248  }
249  else
250  d->qword[0] =
252  d++;
253  }
254  return 0;
255 }
256 
257 clib_error_t *
259 {
260  avf_main_t *am = &avf_main;
261  avf_txq_t *txq;
262  clib_error_t *error = 0;
263 
264  if (qid >= ad->num_queue_pairs)
265  {
266  qid = qid % ad->num_queue_pairs;
267  txq = vec_elt_at_index (ad->txqs, qid);
268  if (txq->lock == 0)
269  clib_spinlock_init (&txq->lock);
270  ad->flags |= AVF_DEVICE_F_SHARED_TXQ_LOCK;
271  return 0;
272  }
273 
275  txq = vec_elt_at_index (ad->txqs, qid);
276  txq->size = AVF_TXQ_SZ;
277  txq->next = 0;
278  txq->descs = vlib_physmem_alloc_aligned (vm, am->physmem_region, &error,
279  txq->size * sizeof (avf_tx_desc_t),
282  txq->qtx_tail = ad->bar0 + AVF_QTX_TAIL (qid);
283  return 0;
284 }
285 
286 typedef struct
287 {
291 
292 void
294 {
295  avf_aq_desc_t *d;
296  u64 pa = ad->arq_bufs_pa + slot * AVF_MBOX_BUF_SZ;
297  d = &ad->arq[slot];
298  memset (d, 0, sizeof (avf_aq_desc_t));
299  d->flags = AVF_AQ_F_BUF;
301  d->addr_hi = (u32) (pa >> 32);
302  d->addr_lo = (u32) pa;
303 }
304 
305 static inline uword
307 {
308  avf_main_t *am = &avf_main;
309  return (ad->flags & AVF_DEVICE_F_IOVA) ?
310  pointer_to_uword (p) :
312 }
313 
314 static void
316 {
317  u64 pa;
318  int i;
319 
320  /* VF MailBox Transmit */
321  memset (ad->atq, 0, sizeof (avf_aq_desc_t) * AVF_MBOX_LEN);
322  ad->atq_bufs_pa = avf_dma_addr (vm, ad, ad->atq_bufs);
323 
324  pa = avf_dma_addr (vm, ad, ad->atq);
325  avf_reg_write (ad, AVF_ATQT, 0); /* Tail */
326  avf_reg_write (ad, AVF_ATQH, 0); /* Head */
327  avf_reg_write (ad, AVF_ATQLEN, AVF_MBOX_LEN | (1 << 31)); /* len & ena */
328  avf_reg_write (ad, AVF_ATQBAL, (u32) pa); /* Base Address Low */
329  avf_reg_write (ad, AVF_ATQBAH, (u32) (pa >> 32)); /* Base Address High */
330 
331  /* VF MailBox Receive */
332  memset (ad->arq, 0, sizeof (avf_aq_desc_t) * AVF_MBOX_LEN);
333  ad->arq_bufs_pa = avf_dma_addr (vm, ad, ad->arq_bufs);
334 
335  for (i = 0; i < AVF_MBOX_LEN; i++)
336  avf_arq_slot_init (ad, i);
337 
338  pa = avf_dma_addr (vm, ad, ad->arq);
339 
340  avf_reg_write (ad, AVF_ARQH, 0); /* Head */
341  avf_reg_write (ad, AVF_ARQT, 0); /* Head */
342  avf_reg_write (ad, AVF_ARQLEN, AVF_MBOX_LEN | (1 << 31)); /* len & ena */
343  avf_reg_write (ad, AVF_ARQBAL, (u32) pa); /* Base Address Low */
344  avf_reg_write (ad, AVF_ARQBAH, (u32) (pa >> 32)); /* Base Address High */
345  avf_reg_write (ad, AVF_ARQT, AVF_MBOX_LEN - 1); /* Tail */
346 
347  ad->atq_next_slot = 0;
348  ad->arq_next_slot = 0;
349 }
350 
351 clib_error_t *
353  void *in, int in_len, void *out, int out_len)
354 {
355  clib_error_t *err;
356  avf_aq_desc_t *d, dt = {.opcode = 0x801,.v_opcode = op };
357  u32 head;
358  int n_retry = 5;
359 
360 
361  /* supppres interrupt in the next adminq receive slot
362  as we are going to wait for response
363  we only need interrupts when event is received */
364  d = &ad->arq[ad->arq_next_slot];
365  d->flags |= AVF_AQ_F_SI;
366 
367  if ((err = avf_aq_desc_enq (vm, ad, &dt, in, in_len)))
368  return err;
369 
370 retry:
371  head = avf_get_u32 (ad->bar0, AVF_ARQH);
372 
373  if (ad->arq_next_slot == head)
374  {
375  if (--n_retry == 0)
376  return clib_error_return (0, "timeout");
377  vlib_process_suspend (vm, 10e-3);
378  goto retry;
379  }
380 
381  d = &ad->arq[ad->arq_next_slot];
382 
383  if (d->v_opcode == VIRTCHNL_OP_EVENT)
384  {
385  void *buf = ad->arq_bufs + ad->arq_next_slot * AVF_MBOX_BUF_SZ;
387 
388  if ((d->datalen != sizeof (virtchnl_pf_event_t)) ||
389  ((d->flags & AVF_AQ_F_BUF) == 0))
390  return clib_error_return (0, "event message error");
391 
392  vec_add2 (ad->events, e, 1);
393  clib_memcpy (e, buf, sizeof (virtchnl_pf_event_t));
395  ad->arq_next_slot++;
396  n_retry = 5;
397  goto retry;
398  }
399 
400  if (d->v_opcode != op)
401  {
402  err = clib_error_return (0, "unexpected message receiver [v_opcode = %u"
403  "expected %u]", d->v_opcode, op);
404  goto done;
405  }
406 
407  if (d->v_retval)
408  {
409  err = clib_error_return (0, "error [v_opcode = %u, v_retval %d]",
410  d->v_opcode, d->v_retval);
411  goto done;
412  }
413 
414  if (d->flags & AVF_AQ_F_BUF)
415  {
416  void *buf = ad->arq_bufs + ad->arq_next_slot * AVF_MBOX_BUF_SZ;
417  clib_memcpy (out, buf, out_len);
418  }
419 
422  avf_reg_flush (ad);
423  ad->arq_next_slot = (ad->arq_next_slot + 1) % AVF_MBOX_LEN;
424 
425 done:
426 
427  if (ad->flags & AVF_DEVICE_F_ELOG)
428  {
429  /* *INDENT-OFF* */
430  ELOG_TYPE_DECLARE (el) =
431  {
432  .format = "avf[%d] send to pf: v_opcode %s (%d) v_retval 0x%x",
433  .format_args = "i4t4i4i4",
434  .n_enum_strings = VIRTCHNL_N_OPS,
435  .enum_strings = {
436 #define _(v, n) [v] = #n,
438 #undef _
439  },
440  };
441  struct
442  {
443  u32 dev_instance;
444  u32 v_opcode;
445  u32 v_opcode_val;
446  u32 v_retval;
447  } *ed;
448  ed = ELOG_DATA (&vm->elog_main, el);
449  ed->dev_instance = ad->dev_instance;
450  ed->v_opcode = op;
451  ed->v_opcode_val = op;
452  ed->v_retval = d->v_retval;
453  /* *INDENT-ON* */
454  }
455  return err;
456 }
457 
458 clib_error_t *
461 {
462  clib_error_t *err = 0;
463  virtchnl_version_info_t myver = {
465  .minor = VIRTCHNL_VERSION_MINOR,
466  };
467 
468  err = avf_send_to_pf (vm, ad, VIRTCHNL_OP_VERSION, &myver,
469  sizeof (virtchnl_version_info_t), ver,
470  sizeof (virtchnl_version_info_t));
471 
472  if (err)
473  return err;
474 
475  return err;
476 }
477 
478 clib_error_t *
481 {
482  clib_error_t *err = 0;
483  u32 bitmap = (VIRTCHNL_VF_OFFLOAD_L2 | VIRTCHNL_VF_OFFLOAD_RSS_AQ |
484  VIRTCHNL_VF_OFFLOAD_RSS_REG | VIRTCHNL_VF_OFFLOAD_WB_ON_ITR |
485  VIRTCHNL_VF_OFFLOAD_VLAN | VIRTCHNL_VF_OFFLOAD_RX_POLLING);
486 
487  err = avf_send_to_pf (vm, ad, VIRTCHNL_OP_GET_VF_RESOURCES, &bitmap,
488  sizeof (u32), res, sizeof (virtchnl_vf_resource_t));
489 
490  if (err)
491  return err;
492 
493  return err;
494 }
495 
496 clib_error_t *
498 {
499  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_DISABLE_VLAN_STRIPPING, 0, 0, 0,
500  0);
501 }
502 
503 clib_error_t *
505 {
506  virtchnl_promisc_info_t pi = { 0 };
507 
508  pi.vsi_id = ad->vsi_id;
509  pi.flags = 1;
510  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_CONFIG_PROMISCUOUS_MODE, &pi,
511  sizeof (virtchnl_promisc_info_t), 0, 0);
512 }
513 
514 
515 clib_error_t *
517 {
518  int i;
519  int n_qp = clib_max (vec_len (ad->rxqs), vec_len (ad->txqs));
520  int msg_len = sizeof (virtchnl_vsi_queue_config_info_t) + n_qp *
522  u8 msg[msg_len];
524 
525  memset (msg, 0, msg_len);
527  ci->vsi_id = ad->vsi_id;
528  ci->num_queue_pairs = n_qp;
529 
530  for (i = 0; i < n_qp; i++)
531  {
532  virtchnl_txq_info_t *txq = &ci->qpair[i].txq;
533  virtchnl_rxq_info_t *rxq = &ci->qpair[i].rxq;
534 
535  rxq->vsi_id = ad->vsi_id;
536  rxq->queue_id = i;
537  rxq->max_pkt_size = 1518;
538  if (i < vec_len (ad->rxqs))
539  {
540  avf_rxq_t *q = vec_elt_at_index (ad->rxqs, i);
541  rxq->ring_len = q->size;
543  rxq->dma_ring_addr = avf_dma_addr (vm, ad, q->descs);
544  avf_reg_write (ad, AVF_QRX_TAIL (i), q->size - 1);
545  }
546 
547  avf_txq_t *q = vec_elt_at_index (ad->txqs, i);
548  txq->vsi_id = ad->vsi_id;
549  if (i < vec_len (ad->txqs))
550  {
551  txq->queue_id = i;
552  txq->ring_len = q->size;
553  txq->dma_ring_addr = avf_dma_addr (vm, ad, q->descs);
554  }
555  }
556 
557  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_CONFIG_VSI_QUEUES, msg, msg_len,
558  0, 0);
559 }
560 
561 clib_error_t *
563 {
564  int count = 1;
565  int msg_len = sizeof (virtchnl_irq_map_info_t) +
566  count * sizeof (virtchnl_vector_map_t);
567  u8 msg[msg_len];
569 
570  memset (msg, 0, msg_len);
571  imi = (virtchnl_irq_map_info_t *) msg;
572  imi->num_vectors = count;
573 
574  imi->vecmap[0].vector_id = 1;
575  imi->vecmap[0].vsi_id = ad->vsi_id;
576  imi->vecmap[0].rxq_map = 1;
577  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_CONFIG_IRQ_MAP, msg, msg_len, 0,
578  0);
579 }
580 
581 clib_error_t *
583 {
584  int msg_len =
585  sizeof (virtchnl_ether_addr_list_t) +
586  count * sizeof (virtchnl_ether_addr_t);
587  u8 msg[msg_len];
589  int i;
590 
591  memset (msg, 0, msg_len);
592  al = (virtchnl_ether_addr_list_t *) msg;
593  al->vsi_id = ad->vsi_id;
594  al->num_elements = count;
595  for (i = 0; i < count; i++)
596  clib_memcpy (&al->list[i].addr, macs + i * 6, 6);
597  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_ADD_ETH_ADDR, msg, msg_len, 0,
598  0);
599 }
600 
601 clib_error_t *
603 {
604  virtchnl_queue_select_t qs = { 0 };
605  qs.vsi_id = ad->vsi_id;
606  qs.rx_queues = rx;
607  qs.tx_queues = tx;
608  avf_rxq_t *rxq = vec_elt_at_index (ad->rxqs, 0);
609  avf_reg_write (ad, AVF_QRX_TAIL (0), rxq->n_bufs);
610  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_ENABLE_QUEUES, &qs,
611  sizeof (virtchnl_queue_select_t), 0, 0);
612 }
613 
614 clib_error_t *
617 {
618  virtchnl_queue_select_t qs = { 0 };
619  qs.vsi_id = ad->vsi_id;
620  return avf_send_to_pf (vm, ad, VIRTCHNL_OP_GET_STATS,
621  &qs, sizeof (virtchnl_queue_select_t),
622  es, sizeof (virtchnl_eth_stats_t));
623 }
624 
625 clib_error_t *
627 {
628  avf_aq_desc_t d = { 0 };
629  clib_error_t *error;
630  u32 rstat;
631  int n_retry = 20;
632 
633  d.opcode = 0x801;
634  d.v_opcode = VIRTCHNL_OP_RESET_VF;
635  if ((error = avf_aq_desc_enq (vm, ad, &d, 0, 0)))
636  return error;
637 
638 retry:
639  vlib_process_suspend (vm, 10e-3);
640  rstat = avf_get_u32 (ad->bar0, AVFGEN_RSTAT);
641 
642  if (rstat == 2 || rstat == 3)
643  return 0;
644 
645  if (--n_retry == 0)
646  return clib_error_return (0, "reset failed (timeout)");
647 
648  goto retry;
649 }
650 
651 clib_error_t *
653 {
654  virtchnl_version_info_t ver = { 0 };
655  virtchnl_vf_resource_t res = { 0 };
656  clib_error_t *error;
658  int i;
659 
660  avf_adminq_init (vm, ad);
661 
662  if ((error = avf_device_reset (vm, ad)))
663  return error;
664 
665  avf_adminq_init (vm, ad);
666 
667  /*
668  * OP_VERSION
669  */
670  if ((error = avf_op_version (vm, ad, &ver)))
671  return error;
672 
673  if (ver.major != VIRTCHNL_VERSION_MAJOR ||
675  return clib_error_return (0, "incompatible protocol version "
676  "(remote %d.%d)", ver.major, ver.minor);
677 
678  /*
679  * OP_GET_VF_RESOUCES
680  */
681  if ((error = avf_op_get_vf_resources (vm, ad, &res)))
682  return error;
683 
684  if (res.num_vsis != 1 || res.vsi_res[0].vsi_type != VIRTCHNL_VSI_SRIOV)
685  return clib_error_return (0, "unexpected GET_VF_RESOURCE reply received");
686 
687  ad->vsi_id = res.vsi_res[0].vsi_id;
690  ad->max_vectors = res.max_vectors;
691  ad->max_mtu = res.max_mtu;
692  ad->rss_key_size = res.rss_key_size;
693  ad->rss_lut_size = res.rss_lut_size;
694 
695  clib_memcpy (ad->hwaddr, res.vsi_res[0].default_mac_addr, 6);
696 
697  /*
698  * Disable VLAN stripping
699  */
700  if ((error = avf_op_disable_vlan_stripping (vm, ad)))
701  return error;
702 
703  if ((error = avf_config_promisc_mode (vm, ad)))
704  return error;
705 
706  if ((error = avf_cmd_rx_ctl_reg_write (vm, ad, 0xc400, 0)))
707  return error;
708 
709  if ((error = avf_cmd_rx_ctl_reg_write (vm, ad, 0xc404, 0)))
710  return error;
711 
712  /*
713  * Init Queues
714  */
715  if ((error = avf_rxq_init (vm, ad, 0)))
716  return error;
717 
718  for (i = 0; i < tm->n_vlib_mains; i++)
719  if ((error = avf_txq_init (vm, ad, i)))
720  return error;
721 
722  if ((error = avf_op_config_vsi_queues (vm, ad)))
723  return error;
724 
725  if ((error = avf_op_config_irq_map (vm, ad)))
726  return error;
727 
728  avf_irq_0_enable (ad);
729  avf_irq_n_enable (ad, 0);
730 
731  if ((error = avf_op_add_eth_addr (vm, ad, 1, ad->hwaddr)))
732  return error;
733 
734  if ((error = avf_op_enable_queues (vm, ad, 1, 0)))
735  return error;
736 
737  if ((error = avf_op_enable_queues (vm, ad, 0, 1)))
738  return error;
739 
740  ad->flags |= AVF_DEVICE_F_INITIALIZED;
741  return error;
742 }
743 
744 void
746 {
747  vnet_main_t *vnm = vnet_get_main ();
749  u32 r;
750 
751  if (ad->flags & AVF_DEVICE_F_ERROR)
752  return;
753 
754  if ((ad->flags & AVF_DEVICE_F_INITIALIZED) == 0)
755  return;
756 
757  ASSERT (ad->error == 0);
758 
759  r = avf_get_u32 (ad->bar0, AVF_ARQLEN);
760  if ((r & 0xf0000000) != (1 << 31))
761  {
762  ad->error = clib_error_return (0, "arq not enabled, arqlen = 0x%x", r);
763  goto error;
764  }
765 
766  r = avf_get_u32 (ad->bar0, AVF_ATQLEN);
767  if ((r & 0xf0000000) != (1 << 31))
768  {
769  ad->error = clib_error_return (0, "atq not enabled, atqlen = 0x%x", r);
770  goto error;
771  }
772 
773  if (is_irq == 0)
774  avf_op_get_stats (vm, ad, &ad->eth_stats);
775 
776  /* *INDENT-OFF* */
777  vec_foreach (e, ad->events)
778  {
780  {
781  int link_up = e->event_data.link_event.link_status;
782  virtchnl_link_speed_t speed = e->event_data.link_event.link_speed;
783  u32 flags = 0;
784 
785  if (link_up && (ad->flags & AVF_DEVICE_F_LINK_UP) == 0)
786  {
787  ad->flags |= AVF_DEVICE_F_LINK_UP;
790  if (speed == VIRTCHNL_LINK_SPEED_40GB)
792  else if (speed == VIRTCHNL_LINK_SPEED_25GB)
794  else if (speed == VIRTCHNL_LINK_SPEED_10GB)
796  else if (speed == VIRTCHNL_LINK_SPEED_1GB)
798  else if (speed == VIRTCHNL_LINK_SPEED_100MB)
800  vnet_hw_interface_set_flags (vnm, ad->hw_if_index, flags);
801  ad->link_speed = speed;
802  }
803  else if (!link_up && (ad->flags & AVF_DEVICE_F_LINK_UP) != 0)
804  {
805  ad->flags &= ~AVF_DEVICE_F_LINK_UP;
806  ad->link_speed = 0;
807  }
808 
809  if (ad->flags & AVF_DEVICE_F_ELOG)
810  {
811  ELOG_TYPE_DECLARE (el) =
812  {
813  .format = "avf[%d] link change: link_status %d "
814  "link_speed %d",
815  .format_args = "i4i1i1",
816  };
817  struct
818  {
819  u32 dev_instance;
820  u8 link_status;
821  u8 link_speed;
822  } *ed;
823  ed = ELOG_DATA (&vm->elog_main, el);
824  ed->dev_instance = ad->dev_instance;
825  ed->link_status = link_up;
826  ed->link_speed = speed;
827  }
828  }
829  else
830  {
831  if (ad->flags & AVF_DEVICE_F_ELOG)
832  {
833  ELOG_TYPE_DECLARE (el) =
834  {
835  .format = "avf[%d] unknown event: event %d severity %d",
836  .format_args = "i4i4i1i1",
837  };
838  struct
839  {
840  u32 dev_instance;
841  u32 event;
842  u32 severity;
843  } *ed;
844  ed = ELOG_DATA (&vm->elog_main, el);
845  ed->dev_instance = ad->dev_instance;
846  ed->event = e->event;
847  ed->severity = e->severity;
848  }
849  }
850  }
851  /* *INDENT-ON* */
852  vec_reset_length (ad->events);
853 
854  return;
855 
856 error:
857  ad->flags |= AVF_DEVICE_F_ERROR;
858  ASSERT (ad->error != 0);
859 }
860 
861 static u32
863 {
864  clib_warning ("TODO");
865  return 0;
866 }
867 
868 static uword
870 {
871  avf_main_t *am = &avf_main;
872  avf_device_t *ad;
873  uword *event_data = 0, event_type;
874  int enabled = 0, irq;
875  f64 last_run_duration = 0;
876  f64 last_periodic_time = 0;
877 
878  while (1)
879  {
880  if (enabled)
881  vlib_process_wait_for_event_or_clock (vm, 5.0 - last_run_duration);
882  else
884 
885  event_type = vlib_process_get_events (vm, &event_data);
886  vec_reset_length (event_data);
887  irq = 0;
888 
889  switch (event_type)
890  {
891  case ~0:
892  last_periodic_time = vlib_time_now (vm);
893  break;
895  enabled = 1;
896  break;
898  enabled = 0;
899  continue;
901  irq = 1;
902  break;
903  default:
904  ASSERT (0);
905  }
906 
907  /* *INDENT-OFF* */
908  pool_foreach (ad, am->devices,
909  {
910  avf_process_one_device (vm, ad, irq);
911  });
912  /* *INDENT-ON* */
913  last_run_duration = vlib_time_now (vm) - last_periodic_time;
914  }
915  return 0;
916 }
917 
918 /* *INDENT-OFF* */
920  .function = avf_process,
921  .type = VLIB_NODE_TYPE_PROCESS,
922  .name = "avf-process",
923 };
924 /* *INDENT-ON* */
925 
926 static void
928 {
930  avf_main_t *am = &avf_main;
932  avf_device_t *ad = pool_elt_at_index (am->devices, pd);
933  u32 icr0;
934 
935  icr0 = avf_reg_read (ad, AVFINT_ICR0);
936 
937  if (ad->flags & AVF_DEVICE_F_ELOG)
938  {
939  /* *INDENT-OFF* */
940  ELOG_TYPE_DECLARE (el) =
941  {
942  .format = "avf[%d] irq 0: icr0 0x%x",
943  .format_args = "i4i4",
944  };
945  /* *INDENT-ON* */
946  struct
947  {
948  u32 dev_instance;
949  u32 icr0;
950  } *ed;
951 
952  ed = ELOG_DATA (&vm->elog_main, el);
953  ed->dev_instance = ad->dev_instance;
954  ed->icr0 = icr0;
955  }
956 
957  avf_irq_0_enable (ad);
958 
959  /* bit 30 - Send/Receive Admin queue interrupt indication */
960  if (icr0 & (1 << 30))
963 }
964 
965 static void
967 {
969  avf_main_t *am = &avf_main;
971  avf_device_t *ad = pool_elt_at_index (am->devices, pd);
972 
973  if (ad->flags & AVF_DEVICE_F_ELOG)
974  {
975  /* *INDENT-OFF* */
976  ELOG_TYPE_DECLARE (el) =
977  {
978  .format = "avf[%d] irq %d: received",
979  .format_args = "i4i2",
980  };
981  /* *INDENT-ON* */
982  struct
983  {
984  u32 dev_instance;
985  u16 line;
986  } *ed;
987 
988  ed = ELOG_DATA (&vm->elog_main, el);
989  ed->dev_instance = ad->dev_instance;
990  ed->line = line;
991  }
992 
993  avf_irq_n_enable (ad, 0);
994 }
995 
996 void
998 {
999  vnet_main_t *vnm = vnet_get_main ();
1000  avf_main_t *am = &avf_main;
1001  int i;
1002 
1003  if (ad->hw_if_index)
1004  {
1008  }
1009 
1011 
1012  vlib_physmem_free (vm, am->physmem_region, ad->atq);
1013  vlib_physmem_free (vm, am->physmem_region, ad->arq);
1014  vlib_physmem_free (vm, am->physmem_region, ad->atq_bufs);
1015  vlib_physmem_free (vm, am->physmem_region, ad->arq_bufs);
1016 
1017  /* *INDENT-OFF* */
1018  vec_foreach_index (i, ad->rxqs)
1019  {
1020  avf_rxq_t *rxq = vec_elt_at_index (ad->rxqs, i);
1021  vlib_physmem_free (vm, am->physmem_region, rxq->descs);
1022  if (rxq->n_bufs)
1023  vlib_buffer_free_from_ring (vm, rxq->bufs, rxq->next, rxq->size,
1024  rxq->n_bufs);
1025  vec_free (rxq->bufs);
1026  }
1027  /* *INDENT-ON* */
1028  vec_free (ad->rxqs);
1029 
1030  /* *INDENT-OFF* */
1031  vec_foreach_index (i, ad->txqs)
1032  {
1033  avf_txq_t *txq = vec_elt_at_index (ad->txqs, i);
1034  vlib_physmem_free (vm, am->physmem_region, txq->descs);
1035  if (txq->n_bufs)
1036  {
1037  u16 first = (txq->next - txq->n_bufs) & (txq->size -1);
1038  vlib_buffer_free_from_ring (vm, txq->bufs, first, txq->size,
1039  txq->n_bufs);
1040  }
1041  vec_free (txq->bufs);
1042  }
1043  /* *INDENT-ON* */
1044  vec_free (ad->txqs);
1045 
1046  clib_error_free (ad->error);
1047  memset (ad, 0, sizeof (*ad));
1048  pool_put (am->devices, ad);
1049 }
1050 
1051 void
1053 {
1054  vnet_main_t *vnm = vnet_get_main ();
1055  avf_main_t *am = &avf_main;
1056  avf_device_t *ad;
1058  clib_error_t *error = 0;
1059 
1060  pool_get (am->devices, ad);
1061  ad->dev_instance = ad - am->devices;
1062  ad->per_interface_next_index = ~0;
1063 
1064  if (args->enable_elog)
1065  ad->flags |= AVF_DEVICE_F_ELOG;
1066 
1067  if ((error = vlib_pci_device_open (&args->addr, avf_pci_device_ids, &h)))
1068  goto error;
1069  ad->pci_dev_handle = h;
1070 
1072 
1073  if ((error = vlib_pci_bus_master_enable (h)))
1074  goto error;
1075 
1076  if ((error = vlib_pci_map_region (h, 0, &ad->bar0)))
1077  goto error;
1078 
1079  if ((error = vlib_pci_register_msix_handler (h, 0, 1, &avf_irq_0_handler)))
1080  goto error;
1081 
1082  if ((error = vlib_pci_register_msix_handler (h, 1, 1, &avf_irq_n_handler)))
1083  goto error;
1084 
1085  if ((error = vlib_pci_enable_msix_irq (h, 0, 2)))
1086  goto error;
1087 
1088  if (am->physmem_region_alloc == 0)
1089  {
1091  error = vlib_physmem_region_alloc (vm, "avf descriptors", 4 << 20, 0,
1092  flags, &am->physmem_region);
1093  if (error)
1094  goto error;
1095  am->physmem_region_alloc = 1;
1096  }
1097  ad->atq = vlib_physmem_alloc_aligned (vm, am->physmem_region, &error,
1098  sizeof (avf_aq_desc_t) * AVF_MBOX_LEN,
1099  64);
1100  if (error)
1101  goto error;
1102 
1103  ad->arq = vlib_physmem_alloc_aligned (vm, am->physmem_region, &error,
1104  sizeof (avf_aq_desc_t) * AVF_MBOX_LEN,
1105  64);
1106  if (error)
1107  goto error;
1108 
1109  ad->atq_bufs = vlib_physmem_alloc_aligned (vm, am->physmem_region, &error,
1110  AVF_MBOX_BUF_SZ * AVF_MBOX_LEN,
1111  64);
1112  if (error)
1113  goto error;
1114 
1115  ad->arq_bufs = vlib_physmem_alloc_aligned (vm, am->physmem_region, &error,
1116  AVF_MBOX_BUF_SZ * AVF_MBOX_LEN,
1117  64);
1118  if (error)
1119  goto error;
1120 
1121  if ((error = vlib_pci_intr_enable (h)))
1122  goto error;
1123 
1124  /* FIXME detect */
1125  ad->flags |= AVF_DEVICE_F_IOVA;
1126 
1127  if ((error = avf_device_init (vm, ad)))
1128  goto error;
1129 
1130  /* create interface */
1131  error = ethernet_register_interface (vnm, avf_device_class.index,
1132  ad->dev_instance, ad->hwaddr,
1134 
1135  if (error)
1136  goto error;
1137 
1139  ad->sw_if_index = sw->sw_if_index;
1140 
1142  avf_input_node.index);
1143 
1144  if (pool_elts (am->devices) == 1)
1147 
1148  return;
1149 
1150 error:
1151  avf_delete_if (vm, ad);
1152  args->rv = VNET_API_ERROR_INVALID_INTERFACE;
1153  args->error = clib_error_return (error, "pci-addr %U",
1154  format_vlib_pci_addr, &args->addr);
1155 }
1156 
1157 static clib_error_t *
1159 {
1160  vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1161  avf_main_t *am = &avf_main;
1163  uword is_up = (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) != 0;
1164 
1165  if (ad->flags & AVF_DEVICE_F_ERROR)
1166  return clib_error_return (0, "device is in error state");
1167 
1168  if (is_up)
1169  {
1172  ad->flags |= AVF_DEVICE_F_ADMIN_UP;
1174  }
1175  else
1176  {
1178  ad->flags &= ~AVF_DEVICE_F_ADMIN_UP;
1179  }
1180  return 0;
1181 }
1182 
1183 /* *INDENT-OFF* */
1185 {
1186  .name = "Adaptive Virtual Function (AVF) interface",
1187  .tx_function = avf_interface_tx,
1188  .format_device = format_avf_device,
1189  .format_device_name = format_avf_device_name,
1190  .admin_up_down_function = avf_interface_admin_up_down,
1191 };
1192 /* *INDENT-ON* */
1193 
1194 clib_error_t *
1196 {
1197  avf_main_t *am = &avf_main;
1198  clib_error_t *error;
1200  int i;
1201 
1202  if ((error = vlib_call_init_function (vm, pci_bus_init)))
1203  return error;
1204 
1207 
1208  /* initialize ptype based loopup table */
1210 
1211  /* *INDENT-OFF* */
1212  vec_foreach_index (i, am->ptypes)
1213  {
1214  avf_ptype_t *p = vec_elt_at_index (am->ptypes, i);
1215  if ((i >= 22) && (i <= 87))
1216  {
1218  p->flags = VNET_BUFFER_F_IS_IP4;
1219  }
1220  else if ((i >= 88) && (i <= 153))
1221  {
1223  p->flags = VNET_BUFFER_F_IS_IP6;
1224  }
1225  else
1228  p->flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
1229  }
1230  /* *INDENT-ON* */
1231 
1232  return 0;
1233 }
1234 
1236 
1237 /*
1238  * fd.io coding-style-patch-verification: ON
1239  *
1240  * Local Variables:
1241  * eval: (c-set-style "gnu")
1242  * End:
1243  */
u8 next_node
Definition: avf.h:151
union virtchnl_pf_event_t::@359 event_data
vmrglw vmrglh hi
format_function_t format_vlib_pci_addr
Definition: pci.h:280
#define vec_foreach_index(var, v)
Iterate over vector indices.
#define AVF_ARQLEN
Definition: virtchnl.h:34
virtchnl_queue_pair_info_t qpair[1]
Definition: virtchnl.h:270
u32 hw_if_index
Definition: avf.h:85
#define AVF_ATQH
Definition: virtchnl.h:27
#define VLIB_PHYSMEM_F_INIT_MHEAP
Definition: physmem.h:57
#define VNET_HW_INTERFACE_FLAG_SPEED_1G
Definition: interface.h:403
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:554
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:699
clib_error_t * avf_init(vlib_main_t *vm)
Definition: device.c:1195
static uword * vlib_process_wait_for_event(vlib_main_t *vm)
Definition: node_funcs.h:619
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:352
#define VLIB_PHYSMEM_F_HUGETLB
Definition: physmem.h:58
void ethernet_delete_interface(vnet_main_t *vnm, u32 hw_if_index)
Definition: interface.c:321
avf_ptype_t * ptypes
Definition: avf.h:166
#define AVF_ATQBAH
Definition: virtchnl.h:32
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
void avf_arq_slot_init(avf_device_t *ad, u16 slot)
Definition: device.c:293
clib_error_t * error
Definition: avf.h:118
u64 atq_bufs_pa
Definition: avf.h:98
virtchnl_vsi_type_t vsi_type
Definition: virtchnl.h:136
clib_error_t * avf_rxq_init(vlib_main_t *vm, avf_device_t *ad, u16 qid)
Definition: device.c:217
virtchnl_vector_map_t vecmap[1]
Definition: virtchnl.h:298
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:227
virtchnl_link_speed_t link_speed
Definition: avf.h:112
#define AVF_ARQBAH
Definition: virtchnl.h:26
static void avf_adminq_init(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:315
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:38
#define AVF_ARQT
Definition: virtchnl.h:30
static clib_error_t * vlib_physmem_region_alloc(vlib_main_t *vm, char *name, u32 size, u8 numa_node, u32 flags, vlib_physmem_region_index_t *idx)
format_function_t format_avf_device
Definition: avf.h:189
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:559
int i
vlib_pci_addr_t addr
Definition: avf.h:173
#define AVF_AQ_F_SI
Definition: virtchnl.h:48
u32 dev_instance
Definition: avf.h:83
#define AVF_QTX_TAIL(q)
Definition: virtchnl.h:37
virtchnl_link_speed_t
Definition: virtchnl.h:169
#define VNET_HW_INTERFACE_FLAG_LINK_UP
Definition: interface.h:390
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:445
static void * vlib_physmem_alloc_aligned(vlib_main_t *vm, vlib_physmem_region_index_t idx, clib_error_t **error, uword n_bytes, uword alignment)
Definition: physmem_funcs.h:97
avf_device_t * devices
Definition: avf.h:160
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:227
static u64 vlib_get_buffer_data_physical_address(vlib_main_t *vm, u32 buffer_index)
Definition: buffer_funcs.h:163
volatile u32 * qtx_tail
Definition: avf.h:68
clib_error_t * avf_op_config_irq_map(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:562
static vlib_node_registration_t avf_process_node
(constructor) VLIB_REGISTER_NODE (avf_process_node)
Definition: device.c:919
#define AVF_ATQLEN
Definition: virtchnl.h:28
vnet_device_class_t avf_device_class
#define AVF_ARQH
Definition: virtchnl.h:31
clib_error_t * avf_device_reset(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:626
clib_error_t * vlib_pci_register_msix_handler(vlib_pci_dev_handle_t h, u32 start, u32 count, pci_msix_handler_function_t *msix_handler)
Definition: pci.c:766
clib_error_t * avf_op_disable_vlan_stripping(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:497
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
virtchnl_ops_t
Definition: virtchnl.h:85
static vnet_sw_interface_t * vnet_get_hw_sw_interface(vnet_main_t *vnm, u32 hw_if_index)
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:448
static uword avf_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
Definition: device.c:869
#define AVF_AQ_F_DD
Definition: virtchnl.h:40
#define AVFINT_ICR0_ENA1
Definition: virtchnl.h:24
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:440
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
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:542
clib_spinlock_t lock
Definition: avf.h:71
#define PCI_DEVICE_ID_INTEL_AVF
Definition: device.c:32
static u32 avf_reg_read(avf_device_t *ad, u32 addr)
Definition: avf.h:240
#define AVF_MBOX_BUF_SZ
Definition: device.c:26
volatile u32 * qrx_tail
Definition: avf.h:57
#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
#define VNET_HW_INTERFACE_FLAG_SPEED_25G
Definition: interface.h:408
clib_error_t * vlib_pci_device_open(vlib_pci_addr_t *addr, pci_device_id_t ids[], vlib_pci_dev_handle_t *handle)
Definition: pci.c:1046
clib_error_t * avf_config_promisc_mode(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:504
#define VLIB_BUFFER_DEFAULT_FREE_LIST_BYTES
Definition: buffer.h:447
int physmem_region_alloc
Definition: avf.h:163
unsigned long u64
Definition: types.h:89
vlib_pci_dev_handle_t pci_dev_handle
Definition: avf.h:86
#define vlib_call_init_function(vm, x)
Definition: init.h:162
virtchnl_ether_addr_t list[1]
Definition: virtchnl.h:313
void * arq_bufs
Definition: avf.h:97
avf_main_t avf_main
Definition: device.c:36
static uword pointer_to_uword(const void *p)
Definition: types.h:131
avf_aq_desc_t * arq
Definition: avf.h:95
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:57
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:446
static heap_elt_t * first(heap_header_t *h)
Definition: heap.c:59
void avf_process_one_device(vlib_main_t *vm, avf_device_t *ad, int is_irq)
Definition: device.c:745
static void avf_irq_n_handler(vlib_pci_dev_handle_t h, u16 line)
Definition: device.c:966
const u32 device_input_next_node_advance[((VNET_DEVICE_INPUT_N_NEXT_NODES/CLIB_CACHE_LINE_BYTES)+1)*CLIB_CACHE_LINE_BYTES]
Definition: devices.c:47
i8 buffer_advance
Definition: avf.h:152
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:461
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:952
static u32 avf_get_u32(void *start, int offset)
Definition: avf.h:194
virtchnl_txq_info_t txq
Definition: virtchnl.h:261
#define AVF_ATQT
Definition: virtchnl.h:35
u32 vlib_pci_dev_handle_t
Definition: pci.h:97
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:273
u64 qword[4]
Definition: avf.h:38
#define ELOG_DATA(em, f)
Definition: elog.h:481
#define AVF_AQ_F_RD
Definition: virtchnl.h:45
#define VIRTCHNL_VERSION_MAJOR
Definition: virtchnl.h:18
clib_error_t * avf_op_enable_queues(vlib_main_t *vm, avf_device_t *ad, u32 rx, u32 tx)
Definition: device.c:602
#define AVF_ITR_INT
Definition: device.c:29
static void avf_reg_flush(avf_device_t *ad)
Definition: avf.h:246
#define AVF_RXQ_SZ
Definition: device.c:27
#define AVF_MBOX_LEN
Definition: device.c:25
#define AVFINT_ICR0
Definition: virtchnl.h:23
static clib_error_t * vlib_pci_bus_master_enable(vlib_pci_dev_handle_t h)
Definition: pci.h:236
void avf_delete_if(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:997
u8 hwaddr[6]
Definition: avf.h:106
u16 atq_next_slot
Definition: avf.h:100
static u32 avf_flag_change(vnet_main_t *vnm, vnet_hw_interface_t *hw, u32 flags)
Definition: device.c:862
static void avf_irq_0_enable(avf_device_t *ad)
Definition: device.c:60
#define AVF_AQ_F_BUF
Definition: virtchnl.h:47
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:143
vlib_main_t * vm
Definition: buffer.c:294
vlib_node_registration_t avf_input_node
(constructor) VLIB_REGISTER_NODE (avf_input_node)
Definition: input.c:404
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:336
clib_error_t * pci_bus_init(vlib_main_t *vm)
Definition: pci.c:251
static void avf_irq_0_disable(avf_device_t *ad)
Definition: device.c:48
Definition: avf.h:54
clib_error_t * avf_op_get_stats(vlib_main_t *vm, avf_device_t *ad, virtchnl_eth_stats_t *es)
Definition: device.c:615
u32 flags
Definition: avf.h:153
#define clib_warning(format, args...)
Definition: error.h:59
#define clib_memcpy(a, b, c)
Definition: string.h:75
struct virtchnl_pf_event_t::@359::@360 link_event
elog_main_t elog_main
Definition: main.h:158
avf_tx_desc_t * descs
Definition: avf.h:72
u8 * format_hexdump(u8 *s, va_list *va)
Definition: std-formats.c:281
#define ELOG_TYPE_DECLARE(f)
Definition: elog.h:439
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:102
virtchnl_ops_t v_opcode
Definition: virtchnl.h:208
#define AVFINT_DYN_CTL0
Definition: virtchnl.h:25
#define VNET_HW_INTERFACE_FLAG_SPEED_10G
Definition: interface.h:406
u16 vsi_id
Definition: avf.h:104
u32 per_interface_next_index
Definition: avf.h:81
clib_error_t * avf_op_add_eth_addr(vlib_main_t *vm, avf_device_t *ad, u8 count, u8 *macs)
Definition: device.c:582
static clib_error_t * avf_interface_admin_up_down(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: device.c:1158
u32 feature_bitmap
Definition: avf.h:105
virtchnl_status_code_t v_retval
Definition: virtchnl.h:213
u32 * bufs
Definition: avf.h:73
#define VNET_HW_INTERFACE_FLAG_FULL_DUPLEX
Definition: interface.h:394
void vlib_pci_device_close(vlib_pci_dev_handle_t h)
Definition: pci.c:1091
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
Definition: interface.h:588
#define ASSERT(truth)
avf_aq_desc_t * atq
Definition: avf.h:94
unsigned int u32
Definition: types.h:88
void vnet_hw_interface_assign_rx_thread(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id, uword thread_index)
Definition: devices.c:138
u32 flags
Definition: avf.h:80
#define AVFINT_DYN_CTLN(x)
Definition: virtchnl.h:22
Definition: avf.h:65
u32 * bufs
Definition: avf.h:61
static void avf_irq_n_enable(avf_device_t *ad, u8 line)
Definition: device.c:87
void * bar0
Definition: avf.h:87
#define PCI_DEVICE_ID_INTEL_X710_VF
Definition: device.c:33
static void vlib_physmem_free(vlib_main_t *vm, vlib_physmem_region_index_t idx, void *mem)
clib_error_t * ethernet_register_interface(vnet_main_t *vnm, u32 dev_class_index, u32 dev_instance, u8 *address, u32 *hw_if_index_return, ethernet_flag_change_function_t flag_change)
Definition: interface.c:273
VNET_DEVICE_CLASS(bond_dev_class)
virtchnl_pf_event_t * events
Definition: avf.h:102
size_t count
Definition: vapi.c:42
virtchnl_event_codes_t event
Definition: virtchnl.h:179
static void avf_reg_write(avf_device_t *ad, u32 addr, u32 val)
Definition: avf.h:234
clib_error_t * avf_op_version(vlib_main_t *vm, avf_device_t *ad, virtchnl_version_info_t *ver)
Definition: device.c:459
static uword avf_dma_addr(vlib_main_t *vm, avf_device_t *ad, void *p)
Definition: device.c:306
#define clib_max(x, y)
Definition: clib.h:333
virtchnl_eth_stats_t eth_stats
Definition: avf.h:115
void * atq_bufs
Definition: avf.h:96
static vlib_main_t * vlib_get_main(void)
Definition: global_funcs.h:23
#define AVFGEN_RSTAT
Definition: virtchnl.h:36
u64 uword
Definition: types.h:112
u16 num_queue_pairs
Definition: avf.h:107
u16 next
Definition: avf.h:69
static void avf_irq_0_handler(vlib_pci_dev_handle_t h, u16 line)
Definition: device.c:927
virtchnl_rxq_info_t rxq
Definition: virtchnl.h:262
#define AVF_ARQBAL
Definition: virtchnl.h:29
u32 rss_lut_size
Definition: avf.h:111
unsigned short u16
Definition: types.h:57
clib_error_t * avf_device_init(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:652
#define VNET_HW_INTERFACE_FLAG_SPEED_100M
Definition: interface.h:402
#define avf_log_debug(fmt,...)
Definition: device.c:45
#define AVF_AQ_F_CMP
Definition: virtchnl.h:41
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
double f64
Definition: types.h:142
unsigned char u8
Definition: types.h:56
format_function_t format_avf_device_name
Definition: avf.h:190
uword vlib_pci_get_private_data(vlib_pci_dev_handle_t h)
Definition: pci.c:134
#define foreach_virtchnl_op
Definition: virtchnl.h:53
static u64 vlib_physmem_virtual_to_physical(vlib_main_t *vm, vlib_physmem_region_index_t idx, void *mem)
u16 size
Definition: avf.h:59
void vlib_pci_set_private_data(vlib_pci_dev_handle_t h, uword private_data)
Definition: pci.c:141
u16 arq_next_slot
Definition: avf.h:101
#define clib_error_free(e)
Definition: error.h:86
clib_error_t * vlib_pci_map_region(vlib_pci_dev_handle_t h, u32 resource, void **result)
Definition: pci.c:1033
avf_rxq_t * rxqs
Definition: avf.h:90
virtchnl_vsi_resource_t vsi_res[1]
Definition: virtchnl.h:150
int vnet_hw_interface_unassign_rx_thread(vnet_main_t *vnm, u32 hw_if_index, u16 queue_id)
Definition: devices.c:187
#define AVF_TXQ_SZ
Definition: device.c:28
clib_error_t * vlib_pci_enable_msix_irq(vlib_pci_dev_handle_t h, u16 start, u16 count)
Definition: pci.c:822
clib_error_t * error
Definition: avf.h:177
static clib_error_t * vlib_pci_intr_enable(vlib_pci_dev_handle_t h)
Definition: pci.h:204
#define VNET_HW_INTERFACE_FLAG_SPEED_40G
Definition: interface.h:409
avf_per_thread_data_t * per_thread_data
Definition: avf.h:161
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
u16 size
Definition: avf.h:70
u8 data[0]
Packet data.
Definition: buffer.h:179
u32 sw_if_index
Definition: avf.h:84
#define vec_foreach(var, vec)
Vector iterator.
u64 arq_bufs_pa
Definition: avf.h:99
#define CLIB_MEMORY_BARRIER()
Definition: clib.h:109
void avf_create_if(vlib_main_t *vm, avf_create_if_args_t *args)
Definition: device.c:1052
#define AVF_ATQBAL
Definition: virtchnl.h:33
u16 n_bufs
Definition: avf.h:74
u32 flags
Definition: vhost-user.h:77
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
#define VIRTCHNL_VERSION_MINOR
Definition: virtchnl.h:19
static u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
Definition: buffer_funcs.h:347
static void avf_irq_n_disable(avf_device_t *ad, u8 line)
Definition: device.c:78
#define PCI_VENDOR_ID_INTEL
Definition: device.c:31
clib_error_t * avf_cmd_rx_ctl_reg_write(vlib_main_t *vm, avf_device_t *ad, u32 reg, u32 val)
Definition: device.c:186
vlib_physmem_region_index_t physmem_region
Definition: avf.h:162
u16 next
Definition: avf.h:58
uword avf_interface_tx(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
Definition: output.c:37
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:57
static void vnet_hw_interface_set_input_node(vnet_main_t *vnm, u32 hw_if_index, u32 node_index)
Definition: devices.h:79
avf_txq_t * txqs
Definition: avf.h:91
avf_rx_desc_t * descs
Definition: avf.h:60
clib_error_t * avf_op_config_vsi_queues(vlib_main_t *vm, avf_device_t *ad)
Definition: device.c:516
u16 vendor_id
Definition: pci.h:120
clib_error_t * avf_txq_init(vlib_main_t *vm, avf_device_t *ad, u16 qid)
Definition: device.c:258
u16 n_bufs
Definition: avf.h:62
#define AVF_AQ_F_ERR
Definition: virtchnl.h:42
u16 max_vectors
Definition: avf.h:108
clib_error_t * avf_op_get_vf_resources(vlib_main_t *vm, avf_device_t *ad, virtchnl_vf_resource_t *res)
Definition: device.c:479
u32 rss_key_size
Definition: avf.h:110
u16 max_mtu
Definition: avf.h:109
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128