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